12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646 |
- function calcLeftShift(bit) { //kaje soll << einbauen
- a = 1;
- a <<= bit;
- return a;
- }
- function sb.getSpacer() {
- return("§0------------------");
- }
- function isString(anything) {
- return string.class(anything) == "String";
- }
- function isBlock(anything) {
- return string.class(anything) == "CraftBlock";
- }
- function getServerConfig() {
- return getScriptVar("server_config");
- }
- function msg.dev(string) {
- msg.string("dev", string.concat("[§eDebug§r] ", string));
- }
- function perm.no(perm, player) {
- msg.prefix(player, "§6Perms", string.concat("You have no permission for §c", perm, "§r."));
- }
- function checkIfEverOnline(player_name) {
- return player.getUuid(player_name) != null;
- }
- function isOnline(player_name) {
- return read.player(player_name) != null;
- }
- function list.copy(list) {
- list_new = list.new();
- iter = iterator(list);
- while(hasNext(iter)) {
- list.add(list_new, next(iter));
- }
- return list_new;
- }
- function list.transfer(from_list, to_list) {
- iter = iterator(from_list);
- while(hasNext(iter)) {
- list.add(to_list, next(iter));
- }
- }
- function array.sort(my_array, ascending) {
- size = array.getSize(my_array);
- if(ascending) {
- for(i = 0; i < size - 1; i++) {
- for(j = i + 1; j < size; j++) {
- if(my_array[j] < my_array[i]) {
- temp = my_array[i];
- my_array[i] = my_array[j];
- my_array[j] = temp;
- }
- }
- }
- } else {
- for(i = 0; i < size - 1; i++) {
- for(j = i + 1; j < size; j++) {
- if(my_array[j] > my_array[i]) {
- temp = my_array[i];
- my_array[i] = my_array[j];
- my_array[j] = temp;
- }
- }
- }
- }
- return my_array;
- }
- function array.contains(array, element) {
- for(i = 0; i < array.getSize(array); i++) {
- if(array[i] == element) {
- return true;
- }
- }
- return false;
- }
- function array.getIndexOf(array, element) {
- for(i = 0; i < array.getSize(array); i++) {
- if(array[i] == element) {
- return i;
- }
- }
- return -1;
- }
- function map.sort(map, ascending) {
- size = map.getSize(map);
- my_array = array.new(size, 2);
- //Map in Array umwandeln
- i = 0;
- iter = map.iterator(map);
- while(hasNext(iter)) {
- element = next(iter);
- key = map.getKey(element);
- value = map.getValue(element);
- my_array[i, 0] = key;
- my_array[i, 1] = value;
- i++;
- }
- //Array sortieren
- if(ascending) {
- for(i = 0; i < size - 1; i++) {
- for(j = i + 1; j < size; j++) {
- if(my_array[j, 1] < my_array[i, 1]) {
- g = my_array[i, 0];
- h = my_array[i, 1];
- my_array[i, 0] = my_array[j, 0];
- my_array[i, 1] = my_array[j, 1];
- my_array[j, 0] = g;
- my_array[j, 1] = h;
- }
- }
- }
- } else {
- for(i = 0; i < size - 1; i++) {
- for(j = i + 1; j < size; j++) {
- if(my_array[j, 1] > my_array[i, 1]) {
- g = my_array[i, 0];
- h = my_array[i, 1];
- my_array[i, 0] = my_array[j, 0];
- my_array[i, 1] = my_array[j, 1];
- my_array[j, 0] = g;
- my_array[j, 1] = h;
- }
- }
- }
- }
- return my_array;
- }
- function getDirection(yaw) {
- while(yaw < 0) {
- yaw += 360;
- }
- while(yaw >= 360) {
- yaw -= 360;
- }
- if(yaw > 60 && yaw < 120) {
- direction = "west";
- } elseif(yaw > 150 && yaw < 210) {
- direction = "north";
- } elseif(yaw > 240 && yaw < 300) {
- direction = "east";
- } elseif(yaw > 330 || yaw < 30) {
- direction = "south";
- } else {
- return null;
- }
- return direction;
- }
- function getDirectionExact(yaw) {
- while(yaw < 0) {
- yaw += 360;
- }
- while(yaw >= 360) {
- yaw -= 360;
- }
- if(yaw > 67.5 && yaw <= 112.5) {
- direction = "West";
- } elseif(yaw > 112.5 && yaw <= 157.5) {
- direction = "North-West";
- } elseif(yaw > 157.5 && yaw <= 202.5) {
- direction = "North";
- } elseif(yaw > 202.5 && yaw <= 247.5) {
- direction = "North-East";
- } elseif(yaw > 247.5 && yaw <= 292.5) {
- direction = "East";
- } elseif(yaw > 292.5 && yaw <= 337.5) {
- direction = "South-East";
- }elseif(yaw > 337.5 || yaw <= 22.5) {
- direction = "South";
- } elseif(yaw > 22.5 && yaw <= 67.5) {
- direction = "South-West";
- }else {
- return null;
- }
- return direction;
- }
- function correctTimeFormat(textnumber) {
- if(string.length(textnumber) == 1) {
- textnumber = string.concat("0", textnumber);
- }
- return textnumber;
- }
- function player.giveSingleItem(player, item) {
- amount = inv.getItemAmount(player.getInv(player), item.getType(item));
- if(amount == 0) {
- player.safeGiveItem(player, item);
- }
- }
- function player.splitGiveItem(player, item, safe_give) {
- amount = item.getAmount(item);
- max_amount = item.getMaxAmount(item);
- max_item = item.clone(item);
- item.setAmount(max_item, max_amount);
- while(amount > max_amount) {
- if(safe_give) {
- player.safeGiveItem(player, max_item);
- } else {
- player.giveItem(player, max_item);
- }
- amount -= max_amount;
- }
- item.setAmount(item, amount);
- if(safe_give) {
- player.safeGiveItem(player, item);
- } else {
- player.safeGiveItem(player, item);
- }
- }
- function getItemFlags() {
- list = list.new();
- list.add(list, "HIDE_ATTRIBUTES");
- list.add(list, "HIDE_UNBREAKABLE");
- list.add(list, "HIDE_DESTROYS");
- list.add(list, "HIDE_PLACED_ON");
- list.add(list, "HIDE_POTION_EFFECTS");
- list.add(list, "HIDE_DYE");
- list.add(list, "HIDE_ENCHANTS");
- return list;
- }
- function getPotionTypes() {
- potion = list.new();
- list.add(potion, "night_vision");
- list.add(potion, "invisibility");
- list.add(potion, "leaping");
- list.add(potion, "fire_resistance");
- list.add(potion, "swiftness");
- list.add(potion, "slowness");
- list.add(potion, "water_breathing");
- list.add(potion, "healing");
- list.add(potion, "harming");
- list.add(potion, "poison");
- list.add(potion, "regeneration");
- list.add(potion, "strength");
- list.add(potion, "weakness");
- list.add(potion, "levitation");
- list.add(potion, "luck");
- list.add(potion, "turtle_master");
- list.add(potion, "slow_falling");
- list.add(potion, "infested");
- list.add(potion, "oozing");
- list.add(potion, "weaving");
- list.add(potion, "wind_charged");
- return potion;
- }
- function player.safeGiveItem(player, item) {
- rest_amount = player.giveItem(player, item);
- if(rest_amount > 0) {
- item.setAmount(item, rest_amount);
- item.drop(item, entity.getLocation(player));
- }
- }
- function block.setIfAir(block, type) {
- if(block.isAir(block)) {
- block.setMaterial(block, material.get(type));
- return true;
- }
- return false;
- }
- //Gesamte Spielzeit eines Spielers inkl. der Online-Spielzeit
- function playtime.getPlayerTotal(player_or_id) {
- player_id = player.getValidId(player_or_id);
- minutes = playtime.getPlayerOnlineMinutes(player_id);
- stmt = databank.prepare("SELECT SUM(leave_time - join_time) FROM playtime WHERE player_id = ?;");
- databank.setInt(stmt, 1, player_id);
- result = databank.execute(stmt);
- if(databank.next(result)) {
- minutes += databank.getLong(result, 1) / 1000 / 60;
- }
- databank.close(result);
- databank.close(stmt);
- return minutes;
- }
- //Spielzeit eines Online-Spielers
- function playtime.getPlayerOnlineMinutes(player_id) {
- stmt = databank.prepare("SELECT join_time FROM playtime WHERE player_id = ? AND leave_time IS NULL;");
- databank.setInt(stmt, 1, player_id);
- result = databank.execute(stmt);
- if(databank.next(result)) {
- minutes = (time.getMillis() - databank.getLong(result, 1)) / 1000 / 60;
- } else {
- minutes = 0;
- }
- databank.close(result);
- databank.close(stmt);
- return minutes;
- }
- function grow(center_loc, radius) {
- crops_tag = block.getTag("minecraft:crops");
- for(x = radius * -1; x <= radius; x++) {
- for(z = radius * -1; z <= radius; z++) {
- for(y = radius * -1; y <= radius; y++) {
- length = math.hypot(x, math.hypot(y, z));
- if(length <= radius) {
- block = block.get(loc.mod(center_loc, x, y, z));
- if(block.hasTag(block, crops_tag)) {
- if(block.isType(block, "minecraft:beetroots")) {
- block.setData(block, read.blockData(string.replace(string.blockData(block.getData(block)), "age=.", "age=3")));
- } else {
- block.setData(block, read.blockData(string.replace(string.blockData(block.getData(block)), "age=.", "age=7")));
- }
- }
- }
- }
- }
- }
- }
- function getBlockLocation(location) {
- world = loc.getWorld(location);
- bx = loc.getBlockX(location);
- by = loc.getBlockY(location);
- bz = loc.getBlockZ(location);
- return loc.new(world, bx, by, bz);
- }
- function time.getDateString(time) {
- calendar = time.new(time);
- day = time.getStringFromNumber(time.getDay(calendar));
- month = time.getStringFromNumber(time.getMonth(calendar));
- year = string.number(time.getYear(calendar));
- return string.concat(day, ".", month, ".", year);
- }
- function time.getCal(year, month, day, hour, minute, second) {
- second = time.getStringFromNumber(second);
- minute = time.getStringFromNumber(minute);
- hour = time.getStringFromNumber(hour);
- day = time.getStringFromNumber(day);
- month = time.getStringFromNumber(month);
- year = string.number(year);
- return time.parse("yyyyMMddHHmmss", string.concat(year, month, day, hour, minute, second));
- }
- function time.getStringFromNumber(number) {
- if(number > 9) {
- return string.number(number);
- }
- return string.concat("0", string.number(number));
- }
- function time.getClockString(time) { //s
- return string.concat(string.number(math.roundDown(time / 60)), " min ", string.number(math.round(time % 60)), " s");
- }
- function time.getString(millis) {
- calendar = time.new(millis);
- day = time.getStringFromNumber(time.getDay(calendar));
- month = time.getStringFromNumber(time.getMonth(calendar));
- year = time.getYear(calendar);
- hour = time.getStringFromNumber(time.getHour(calendar));
- minute = time.getStringFromNumber(time.getMinute(calendar));
- timestring = string.concat(day, ".", month, ".", string.number(year), " ", hour, ":", minute);
- return timestring;
- }
- /*
- * returns true if a whole day is skipped. (technial: if between the timestamps are two midnights)
- * precondition: timestamp_1 < timestamp_2
- */
- function time.hasWholeDaySkipped(timestamp_1, timestamp_2) {
- cal_1 = time.new(timestamp_1);
- time.nextDay(cal_1); // first midnight after timestamp_1
- time.nextDay(cal_1); // second midnight after timestamp_1
- midnight = time.from(cal_1); // timestamp of 2nd midnight
- return midnight < timestamp_2;
- }
- /*
- * returns true if timestamp_2 is within the next day of timestamp_1
- * precondition: timestamp_1 < timestamp_2
- */
- function isFollowingDay(timestamp_1, timestamp_2) {
- cal_1 = time.new(timestamp_1);
- time.nextDay(cal_1);
- mid_1 = time.from(cal_1);
- diff = timestamp_2 - mid_1;
- return diff > 0 && diff < 86400000;
- }
- function isSameDay(timestamp_1, timestamp_2) {
- cal_1 = time.new(timestamp_1);
- cal_2 = time.new(timestamp_2);
- time.nextDay(cal_1);
- time.nextDay(cal_2);
- mid_1 = time.from(cal_1);
- mid_2 = time.from(cal_2);
- return mid_1 == mid_2;
- }
- function player.hasMinigame(player) {
- id_set = player.getMinigameIds(player);
- if(set.getSize(id_set) > 0) {
- return true;
- }
- return false;
- }
- function player.getMinigameIds(player) {
- set = data.get(player, "minigames_set");
- if(set == null) {
- set = set.new();
- data.set(player, "minigames_set", set);
- }
- return set;
- }
- function player.resetMinigames(player) {
- id_set = player.getMinigameIds(player);
- set.clear(id_set);
- }
- function tjr.getWholeModule(player_or_id) {
- return ranking.getPoints("tjrranks", player_or_id);
- }
- function tjr.getWholeTime(player_or_id) {
- return ranking.getSecPoints("tjrranks", player_or_id);
- }
- function ranking.getPoints(rankingtable, player_or_id) {
- player_id = player.getValidId(player_or_id);
- stmt = databank.prepare(string.concat("SELECT points FROM ", rankingtable, " WHERE player_id = ?;"));
- databank.setInt(stmt, 1, player_id);
- result = databank.execute(stmt);
- if(databank.next(result)) {
- points = databank.getInt(result, 1);
- } else {
- points = 0;
- }
- databank.close(result);
- databank.close(stmt);
- return points;
- }
- function ranking.getSecPoints(rankingtable, player_or_id) {
- player_id = player.getValidId(player_or_id);
- stmt = databank.prepare(string.concat("SELECT sec_points FROM ", rankingtable, " WHERE player_id = ?;"));
- databank.setInt(stmt, 1, player_id);
- result = databank.execute(stmt);
- if(databank.next(result)) {
- sec_points = databank.getInt(result, 1);
- } else {
- sec_points = 0;
- }
- databank.close(result);
- databank.close(stmt);
- return sec_points;
- }
- function registerNewbie(id, time) {
- stmt = databank.prepare("INSERT INTO newbies (player_id, time) VALUES(?,?);");
- databank.setInt(stmt, 1, id);
- databank.setLong(stmt, 2, time);
- databank.workerExecute(stmt);
- }
- //--------------------------------------------------
- //ModTimer-Utils
- //--------------------------------------------------
- function modTimer.scriptCallEvent(event, script) {
- modTimer(-20);
- if(script == null) {
- script.callEvent(event);
- return;
- }
- script.callEvent(event, script);
- }
- function modTimer.entityTeleport(entity, location) {
- modTimer(-15);
- entity.teleport(entity, location);
- }
- //--------------------------------------------------
- //World-Utils
- //--------------------------------------------------
- function read.location(string) {
- a = string.split(":", string);
- w = world.get(a[0]);
- x = read.number(a[1]);
- y = read.number(a[2]);
- z = read.number(a[3]);
- if(array.getSize(a) > 4) {
- yaw = read.number(a[4]);
- pitch = read.number(a[5]);
- } else {
- yaw = 0;
- pitch = 0;
- }
- return loc.new(w, x, y, z, yaw, pitch);
- }
- function string.location(location) {
- w = world.getName(loc.getWorld(location));
- x = loc.getX(location);
- y = loc.getY(location);
- z = loc.getZ(location);
- yaw = loc.getYaw(location);
- pitch = loc.getPitch(location);
- return string.concat(w, ":", x, ":", y, ":", z, ":", yaw, ":", pitch);
- }
- function world.getServerSpawn() {
- return read.location(config.getString(getServerConfig(), "serverspawn", "world:0:0:0"));
- }
- function world.getGamesSpawn() {
- return read.location(config.getString(getServerConfig(), "gamesspawn", "world:0:0:0"));
- }
- function world.getCreativeSpawn() {
- return read.location(config.getString(getServerConfig(), "creativespawn", "world:0:0:0"));
- }
- function world.getOverWorld() {
- return world.get("world");
- }
- function world.getTheEnd() {
- return world.get("world_the_end");
- }
- function world.getTheNether() {
- return world.get("world_nether");
- }
- function world.getGames() {
- return world.get("games");
- }
- function world.getCreative() {
- return world.get("creative");
- }
- function world.isCreativeName(world_name) {
- return world_name == "creative";
- }
- function world.isGamesName(world_name) {
- return world_name == "games";
- }
- function world.isOverworld(world_name) {
- return world_name == "world";
- }
- function world.isSurvName(world_name) {
- if(world_name == "world") {
- return true;
- } elseif(world_name == "world_the_end") {
- return true;
- } elseif(world_name == "world_nether") {
- return true;
- }
- return false;
- }
- function world.canUsePlots(world) {
- world_name = world.getName(world);
- if(world.isSurvName(world_name)) {
- return true;
- }
- if(world.isCreativeName(world_name)) {
- return true;
- }
- return false;
- }
- function world.addTimedStatus(world, index, time, message) {
- return;
- world_name = world.getName(world);
- if(world.isSurvName(world_name)) {
- worldlist = world.getPlayers(world.getOverWorld());
- for(i = 0; i < list.getSize(worldlist); i++) {
- status.addTimed(list.getIndex(worldlist, i), index, time, message);
- }
- worldlist = world.getPlayers(world.getTheEnd());
- for(i = 0; i < list.getSize(worldlist); i++) {
- status.addTimed(list.getIndex(worldlist, i), index, time, message);
- }
- worldlist = world.getPlayers(world.getTheNether());
- for(i = 0; i < list.getSize(worldlist); i++) {
- status.addTimed(list.getIndex(worldlist, i), index, time, message);
- }
- return;
- }
- worldlist = world.getPlayers(world);
- for(i = 0; i < list.getSize(worldlist); i++) {
- status.addTimed(list.getIndex(worldlist, i), index, time, message);
- }
- }
- function world.giveItem(world, item) {
- world_list = woorld.getPlayers(world);
- iter = iterator(world_list);
- while(hasNext(iter)) {
- player.safeGiveItem(next(iter), item);
- }
- }
- //--------------------------------------------------
- //Inv-Utils
- //--------------------------------------------------
- function player.checkForWorldChange(player, location) {
- from_world = loc.getWorld(entity.getLocation(player));
- to_world = loc.getWorld(location);
- //Wenn ignore aktiviert --> kein Wechsel
- if(player.hasInvIgnore(player)) {
- return false;
- }
- from_world_name = world.getName(from_world);
- to_world_name = world.getName(to_world);
- //Wenn in selber Welt --> kein Wechsel
- if(from_world == to_world) {
- return false;
- }
- //Wenn beide Welten in derselben Liste sind --> kein Wechsel
- if(world.isSurvName(from_world_name) && world.isSurvName(to_world_name)) {
- return false;
- }
- return true;
- }
- function player.changeInv(player, from_world, to_world) {
- from_world_name = world.getName(from_world);
- to_world_name = world.getName(to_world);
- //Inventory
- inv.saveForPlayer(player, player, from_world);
- inv.loadFromPlayer(player, player, to_world);
- if(perm.has("isTeam", player)) {
- if(perm.has("isSupporter", player) && !perm.has("isAdmin", player) && !perm.has("isMod", player)) {
- player.changeGamemode(player, to_world_name);
- }
- } else {
- player.changeGamemode(player, to_world_name);
- }
- if(world.isSurvName(to_world_name)) {
- if(player.hasFly(player)) {
- scheduler.addFly(5, player, true);
- }
- }
- }
- function player.changeGamemode(player, to_world_name) {
- if(!player.isSpectator(player)) {
- if(to_world_name == "creative") {
- if(perm.has("creative.gm1", player)) {
- gm = "CREATIVE";
- } else {
- gm = "ADVENTURE";
- scheduler.addFly(5, player, true);
- }
- } else {
- gm = "SURVIVAL";
- }
- player.setGamemode(player, gm);
- duration = data.getTimer(player, "fly");
- if(world.isSurvName(to_world_name) && duration > 0) {
- scheduler.addFly(5, player, true);
- }
- }
- }
- function inv.backup(p_or_id) {
- player_id = player.getValidId(p_or_id);
- from_file = file.new(string.concat("scripts/configs/inv_data/survival/", player_id, ".snuvic"));
- if(!file.exists(from_file)) {
- return;
- }
-
- dir = file.new(string.concat("scripts/configs/inv_data/backup/", player_id));
- if(!file.exists(dir)) {
- file.createFolder(dir);
- }
-
- f_map = map.new();
- file_list = file.getList(dir);
- iter = iterator(file_list);
- while(hasNext(iter)) {
- f = next(iter);
- f_name = file.getName(f);
- split_array = string.split("_", f_name);
- number = read.number(split_array[1]);
- a = array.new(2);
- a[0] = f;
- a[1] = split_array[2];
- map.add(f_map, number, a);
- }
-
- number_of_backups = 10;
- for(i = number_of_backups; i > 0; i--) {
- a = map.get(f_map, i);
- if(a == null) {
- continue;
- }
- f = a[0];
- timestamp = a[1];
- if(i == number_of_backups) {
- file.delete(f);
- continue;
- }
- new_f_name = string.concat("backup_", string.number(i + 1), "_", timestamp);
- file.rename(f, file.new(string.concat("scripts/configs/inv_data/backup/", player_id, "/", new_f_name)));
- }
-
- cal = time.new(time.getMillis());
- year = string.number(time.getYear(cal));
- month = string.number(time.getMonth(cal));
- day = string.number(time.getDay(cal));
- hour = string.number(time.getHour(cal));
- min = string.number(time.getMinute(cal));
- sec = string.number(time.getSecond(cal));
- new_f = file.new(string.concat(dir, "/backup_", string.number(1), "_", year, "-", month, "-", day, "-", hour, "-", min, "-", sec));
- f_list = file.read(from_file);
- file.write(new_f, f_list);
- }
- function inv.saveForPlayer(sec_player, for_player_or_id, world) {
- if(isPlayer(for_player_or_id)) {
- for_player_or_id = player.getId(for_player_or_id);
- }
- world_name = world.getName(world);
- if(world.isSurvName(world_name)) {
- inv.backup(for_player_or_id);
- pfad = "scripts/configs/inv_data/survival";
- } else {
- pfad = string.concat("scripts/configs/inv_data/", world_name);
- }
- config = config.new(pfad, for_player_or_id);
-
- //Allgemeine Daten
- if(for_player_or_id == player.getId(sec_player)) {
- config.set(config, "health", living.getHealth(sec_player));
- config.set(config, "hunger", player.getHunger(sec_player));
- config.set(config, "saturation", player.getSaturation(sec_player));
- config.set(config, "xp", player.getExp(sec_player));
- config.set(config, "lvl", player.getLevel(sec_player));
- }
-
- //Inventare
- inv = player.getInv(sec_player);
- for(i = 0; i < 36; i++) {
- item_string = string.item(inv.getItem(inv, i));
- config.set(config, string.concat("slot-", i), item_string);
- }
- ender_inv = player.getEnderInv(sec_player);
- for(i = 0; i < 27; i++) {
- item_string = string.item(inv.getItem(ender_inv, i));
- config.set(config, string.concat("eslot-", i), item_string);
- }
- config.set(config, "offhand", string.item(living.getOffHand(sec_player)));
- config.set(config, "head", string.item(living.getEquip(sec_player, read.slot("HEAD"))));
- config.set(config, "chest", string.item(living.getEquip(sec_player, read.slot("CHEST"))));
- config.set(config, "legs", string.item(living.getEquip(sec_player, read.slot("LEGS"))));
- config.set(config, "feet", string.item(living.getEquip(sec_player, read.slot("FEET"))));
- config.saveAsync(config);
- }
- function inv.loadFromPlayer(sec_player, from_player_or_id, world) {
- if(isPlayer(from_player_or_id)) {
- from_player_or_id = player.getId(from_player_or_id);
- }
- world_name = world.getName(world);
- if(world.isSurvName(world_name)) {
- pfad = "scripts/configs/inv_data/survival";
- } else {
- pfad = string.concat("scripts/configs/inv_data/", world_name);
- }
- config = config.new(pfad, from_player_or_id);
- if(config.exists(config)) {
- config.load(config);
- }
-
- //Allgemeine Daten
- if(from_player_or_id == player.getId(sec_player)) {
- health = config.getDouble(config, "health", 20);
- if(health > 20) {
- health = 20;
- }
- living.setHealth(sec_player, health);
- player.setHunger(sec_player, config.getDouble(config, "hunger", 20));
- player.setSaturation(sec_player, config.getDouble(config, "saturation", 5));
- player.setExp(sec_player, config.getDouble(config, "xp", 0));
- player.setLevel(sec_player, config.getDouble(config, "lvl", 0));
- }
-
- //Inventare
- air_string = item.getAirString();
- for(i = 0; i <= 35; i++) {
- item_string = config.getString(config, string.concat("slot-", i), air_string);
- item = read.item(item_string);
- if(item != null) {
- inv = player.getInv(sec_player);
- inv.setItem(inv, i, item);
- }
- }
- for(i = 0; i < 27; i++) {
- item_string = config.getString(config, string.concat("eslot-", i), air_string);
- item = read.item(item_string);
- if(item != null) {
- ender_inv = player.getEnderInv(sec_player);
- inv.setItem(ender_inv, i, item);
- }
- }
- living.setEquip(sec_player, read.slot("OFF_HAND"), read.item(config.getString(config, "offhand", air_string)));
- living.setEquip(sec_player, read.slot("HEAD"), read.item(config.getString(config, "head", air_string)));
- living.setEquip(sec_player, read.slot("CHEST"), read.item(config.getString(config, "chest", air_string)));
- living.setEquip(sec_player, read.slot("LEGS"), read.item(config.getString(config, "legs", air_string)));
- living.setEquip(sec_player, read.slot("FEET"), read.item(config.getString(config, "feet", air_string)));
- }
- function inv.getItemAmount(inv, wusi) {
- //wusi: item_stack or item_type or item_tag
- c = 0;
- if(isMaterial(wusi)) {
- for(i = 0; i < inv.getSize(inv); i++) {
- item = inv.getItem(inv, i);
- if(item == null) {
- continue;
- }
- if(item.getType(item) == wusi) {
- c += item.getAmount(item);
- }
- }
- } elseif(isItemstack(wusi)) {
- for(i = 0; i < inv.getSize(inv); i++) {
- item = inv.getItem(inv, i);
- if(item == null) {
- continue;
- }
- if(isSameItem(item, wusi)) {
- c += item.getAmount(item);
- }
- }
- } else {
- for(i = 0; i < inv.getSize(inv); i++) {
- item = inv.getItem(inv, i);
- if(item == null) {
- continue;
- }
- if(item.hasTag(item, wusi)) {
- c += item.getAmount(item);
- }
- }
- }
- return c;
- }
- function inv.addItem(inv, itemstack) {
- //adds an item and returns the amount which could not be added
- amount_to_add = item.getAmount(itemstack);
- for(i = 0; i < inv.getSize(inv); i++) {
- item = inv.getItem(inv, i);
- if(item == null) {
- space = item.getMaxAmount(itemstack);
- item = item.clone(itemstack);
- if(space <= amount_to_add) {
- item.setAmount(item, space);
- inv.setItem(inv, i, item);
- amount_to_add -= space;
- if(amount_to_add == 0) {
- break;
- }
- } else {
- item.setAmount(item, amount_to_add);
- inv.setItem(inv, i, item);
- amount_to_add = 0;
- break;
- }
- }
- elseif(isSameItem(item, itemstack)) {
- a = item.getAmount(item);
- max_a = item.getMaxAmount(item);
- space = max_a - a;
- if(space > 0) {
- if(space <= amount_to_add) {
- item.setAmount(item, max_a);
- amount_to_add -= space;
- if(amount_to_add == 0) {
- break;
- }
- } else {
- item.setAmount(item, a + amount_to_add);
- amount_to_add = 0;
- break;
- }
- }
- }
- }
- return amount_to_add;
- }
- function inv.removeItem(inv, itemstack) {
- //removes items and returns the amount which could not be removed
- amount_to_remove = item.getAmount(itemstack);
- for(i = 0; i < inv.getSize(inv); i++) {
- item = inv.getItem(inv, i);
- if(item == null) {
- continue;
- }
- if(isSameItem(item, itemstack)) {
- a = item.getAmount(item);
- if(a <= amount_to_remove) {
- inv.setItem(inv, i, null);
- amount_to_remove -= a;
- if(amount_to_remove == 0) {
- break;
- }
- } else {
- item.setAmount(item, a - amount_to_remove);
- amount_to_remove = 0;
- break;
- }
- }
- }
- return amount_to_remove;
- }
- function inv.removeItem2(inv, wusi, amount_to_remove) {
- //wusi: item_type or item_tag
- //removes items and returns the amount which could not be removed
- if(isMaterial(wusi)) {
- for(i = 0; i < inv.getSize(inv); i++) {
- item = inv.getItem(inv, i);
- if(item == null) {
- continue;
- }
- if(item.getType(item) == wusi) {
- a = item.getAmount(item);
- if(a <= amount_to_remove) {
- inv.setItem(inv, i, null);
- amount_to_remove -= a;
- if(amount_to_remove == 0) {
- break;
- }
- } else {
- item.setAmount(item, a - amount_to_remove);
- amount_to_remove = 0;
- break;
- }
- }
- }
- } else {
- for(i = 0; i < inv.getSize(inv); i++) {
- item = inv.getItem(inv, i);
- if(item == null) {
- continue;
- }
- if(item.hasTag(item, wusi)) {
- a = item.getAmount(item);
- if(a <= amount_to_remove) {
- inv.setItem(inv, i, null);
- amount_to_remove -= a;
- if(amount_to_remove == 0) {
- break;
- }
- } else {
- item.setAmount(item, a - amount_to_remove);
- amount_to_remove = 0;
- break;
- }
- }
- }
- }
- return c;
- }
- //--------------------------------------------------
- //Text-Utils
- //--------------------------------------------------
- function text.getClickText(show_text, execute_string) {
- return text.click(show_text, execute_string);
- }
- function text.getHoverText(show_text, execute_string) {
- return text.hover(show_text, text.new(execute_string));
- }
- //--------------------------------------------------
- //String-Utils
- //--------------------------------------------------
- function string.getHoverText(show_string, execute_string) {
- return text.hover(text.new(show_string), text.new(execute_string));
- }
- function string.getClipBoardText(show_string, copy_string) {
- return text.clipBoard(text.new(show_string), copy_string);
- }
- function string.getInterpretedText(string) {
- start_index = string.indexOf(string, "%link", 0);
- if(start_index == -1) {
- return text.new(string);
- }
- start_text = text.new(string.subString(string, 0, start_index));
- show_index = start_index + 6;
- link_index = string.indexOf(string, " ", show_index) + 1;
- show_string = string.subString(string, show_index, link_index - 1);
- end_index = string.indexOf(string, " ", link_index) + 1;
- link_string = string.subString(string, link_index, end_index - 1);
- rest_string = string.subString(string, end_index, string.length(string));
- return text.merge(start_text, string.getLinkText(show_string, link_string), text.new(rest_string));
- }
- function string.getPrefix(string) {
- return string.concat("§r[", string, "§r]");
- }
- function string.removeFormat(string) {
- return string.replace(string, "§.", "");
- }
- function string.getLinkText(show_string, link_string) {
- return text.link(text.new(show_string), link_string);
- }
- function string.getClickText(show_string, execute_string) {
- return text.click(text.new(show_string), execute_string);
- }
- function string.getSpacer() {
- return("§0-------------------------------------------------");
- }
- function string.concatList(list, connector, from_index, to_index) {
- for(i = from_index; i <= to_index; i++) {
- element = list.getIndex(list, i);
- if(i == from_index) {
- string = element;
- } else {
- string = string.concat(string, connector, element);
- }
- }
- return string;
- }
- function string.onlyLetters(string) {
- a_code = string.charcode("a", 0);
- z_code = string.charcode("z", 0);
- oe_code = string.charcode("ö", 0);
- ae_code = string.charcode("ä", 0);
- ue_code = string.charcode("ü", 0);
- cap_a_code = string.charcode("A", 0);
- cap_z_code = string.charcode("Z", 0);
- cap_oe_code = string.charcode("Ö", 0);
- cap_ae_code = string.charcode("Ä", 0);
- cap_ue_code = string.charcode("Ü", 0);
-
- for(i = 0; i < string.length(string); i++) {
- char_code = string.charcode(string, i);
- }
- if(char_code >= a_code && char_code <= z_code) {
- return true;
- }
- if(char_code >= cap_a_code && char_code <= cap_z_code) {
- return true;
- }
- if(char_code == ae_code || char_code == cap_ae_code) {
- return true;
- }
- if(char_code == oe_code || char_code == cap_oe_code) {
- return true;
- }
- if(char_code == ue_code || char_code == cap_ue_code) {
- return true;
- }
- return false;
- }
- function string.upperFirstLetter(string) {
- length = string.length(string);
- first_letter = string.subString(string, 0, 1);
- rest = string.substring(string, 1, length);
- return string.concat(string.toUpperCase(first_letter), rest);
- }
- function string.getTextWithLink(string) {
- if(string.contains(string, "https://")) {
- https_index = string.indexOf(string, "https://", 0);
- space_index = string.indexOf(string, " ", https_index);
- length = string.length(string);
- if(https_index == 0) {
- msg_before = "";
- } else {
- msg_before = string.subString(string, 0, https_index);
- }
- if(space_index == -1) {
- string_link = string.subString(string, https_index, length);
- msg_after = "";
- } else {
- string_link = string.subString(string, https_index, space_index);
- msg_after = string.subString(string, space_index, length);
- }
- text_link = string.getLinkText(string_link, string_link);
- return text.merge(text.new(msg_before), text_link, text.new(msg_after));
- }
- return text.new(string);
- }
- function string.intelligentSplit(string) {
- list = list.new();
- from_index = 0;
- to_index = 0;
- split_after = 25;
- split_index = split_after;
- whole_length = string.length(string);
-
- while(true) {
- to_index = string.indexOf(string, " ", split_index);
- if(to_index == -1) {
- sub_string = string.subString(string, from_index, string.length(string));
- list.add(list, text.new(sub_string));
- break;
- }
- sub_string = string.subString(string, from_index, to_index);
- list.add(list, text.new(sub_string));
- from_index = to_index + 1;
- split_index += split_after;
- }
-
- return list;
- }
- //--------------------------------------------------
- //Quest-Utils
- //--------------------------------------------------
- function quest.display(player, quest_name, stage, all_stages) {
- sb.add(player, 10, string.concat("§dQuest: ", quest_name, " [", string.number(stage), "/", string.number(all_stages), "]"));
- }
- function quest.removeDisplay(player) {
- sb.remove(player, 10);
- }
- function quest.getIds() {
- return getScriptVar("quest_ids");
- }
- function quest.addPlayer(script, player) {
- quest_ids = quest.getIds();
- map.add(quest_ids, player.getUuid(player), script.getId(script));
- }
- function quest.removePlayer(player) {
- quest_ids = quest.getIds();
- map.remove(quest_ids, player.getUuid(player));
- }
- function player.hasQuest(player) {
- quest_ids = quest.getIds();
- return map.contains(quest_ids, player.getUuid(player));
- }
- function quest.getFromPlayer(player) {
- quest_ids = quest.getIds();
- return map.get(quest_ids, player.getUuid(player));
- }
- function player.isQuester(player, script) {
- if(player == null) {
- return false;
- }
- if(script == null) {
- return false;
- }
- script_id = script.getId(script);
- quest_ids = quest.getIds();
- return map.get(quest_ids, player.getUuid(player)) == script_id;
- }
- function quest.getCounter(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getDouble(config, "quests_solved", 0);
- }
- function quest.setCounter(player_or_id, amount) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "quests_solved", amount);
- config.saveAsync(config);
- }
- function quest.addCounter(player, amount) {
- config = playerdata.getSurvival(player);
- new_amount = config.getDouble(config, "quests_solved", 0) + amount;
- config.set(config, "quests_solved", new_amount);
- config.saveAsync(config);
- if(new_amount == 500) {
- offerRank(player, "rank.altruist");
- perm.addGroupToPlayer(player.getId(player), 17);
- waitfor(20);
- } elseif(new_amount == 50) {
- offerRank(player, "rank.friend");
- } elseif(new_amount == 15) {
- offerRank(player, "rank.volunteer");
- }
- }
- function quest.finish(script, player) {
- sound = sound.get("entity.experience_orb.pickup");
- category = sound.getCategory("MASTER");
- sound.spawnForPlayer(player, sound, category);
- quest.addCounter(player, 1);
- quest.term(script, player);
- }
- function quest.finishReward(script, player, reward) {
- msg.string(player, string.concat("§dQuest finished. §rReward: ", money.getString(reward)));
- money.addBoost(player, reward);
- sound = sound.get("entity.experience_orb.pickup");
- category = sound.getCategory("MASTER");
- sound.spawnForPlayer(player, sound, category);
- quest.addCounter(player, 1);
- quest.term(script, player);
- }
- function quest.term(script, player) {
- quest.removeDisplay(player);
- quest.removePlayer(player);
- script.term(script);
- }
- function script.isActiveName(script_name) {
- script = script.get(script_name);
- if(script == null) {
- return false;
- }
- return true;
- }
- //--------------------------------------------------
- //Slot-Utils
- //--------------------------------------------------
- function slot.getHand() {
- return read.slot("HAND");
- }
- function slot.getOffHand() {
- return read.slot("OFF_HAND");
- }
- function slot.getHead() {
- return read.slot("HEAD");
- }
- function slot.getChest() {
- return read.slot("CHEST");
- }
- function slot.getLegs() {
- return read.slot("LEGS");
- }
- function slot.getFeet() {
- return read.slot("FEET");
- }
- function slot.isHand(slot) {
- return slot == slot.getHand();
- }
- function slot.isOffHand(slot) {
- return slot == slot.getOffHand();
- }
- function slot.isHead(slot) {
- return slot == slot.getHead();
- }
- function slot.isChest(slot) {
- return slot == slot.getChest();
- }
- function slot.isLegs(slot) {
- return slot == slot.getLegs();
- }
- function slot.isFeet(slot) {
- return slot == slot.getFeet();
- }
- //--------------------------------------------------
- //Player-Data-Utils
- //--------------------------------------------------
- function player.teleport(player, location, setBackPos) {
- player_uuid = player.getUuid(player);
- if(player.isOnAdventure(player)) {
- msg.string(player, "[§5Adventure§r] Teleport blocked. ", string.getClickText("[§5Cancel Adventure?§r]", string.concat("/stopadventure ", player)));
- return false;
- }
- if(player.hasMinigame(player)) {
- return false;
- }
- passengers = entity.getPassengers(player);
- iter = iterator(passengers);
- while(hasNext(iter)) {
- entity.unmount(next(iter));
- }
- if(setBackPos) {
- player.setBackPos(player);
- }
- player_loc = entity.getLocation(player);
- from_world = loc.getWorld(player_loc);
- from_world_name = world.getName(from_world);
- to_world = loc.getWorld(location);
- to_world_name = world.getName(to_world);
- world_change = player.checkForWorldChange(player, location);
- if(world_change) {
- //Inventory
- player.changeInv(player, from_world, to_world);
- living.clearEffects(player);
- //Party
- if(player.isInParty(player) && player.isPartyLeader(player)) {
- party_id = player.getPartyId(player);
- party_list = party.getList(party_id);
- iter = iterator(party_list);
- while(hasNext(iter)) {
- p = player.get(next(iter));
- if(player_uuid == player.getUuid(p)) {
- continue;
- }
- p_name = player.getName(p);
- if(!loc.isSameWorld(player_loc, entity.getLocation(p))) {
- msg.prefix(player, "§5Party", string.concat(p_name, "§c is in another world."));
- continue;
- }
- if(player.hasMinigame(p)) {
- msg.prefix(player, "§5Party", string.concat(p_name, "§c is in a game."));
- continue;
- }
- if(player.hasQuest(p)) {
- msg.prefix(player, "§5Party", string.concat(p_name, "§c is doing a quest."));
- continue;
- }
- if(player.isOnAdventure(p)) {
- msg.prefix(player, "§5Party", string.concat(p_name, "§c is on an adventure."));
- continue;
- }
- if(player.isAfk(p)) {
- msg.prefix(player, "§5Party", string.concat(p_name, "§c is afk."));
- continue;
- }
- player.teleport(p, location, setBackPos);
- }
- }
- //Quests
- script_id = quest.getFromPlayer(player);
- if(script_id != null) {
- script = script.getFromId(script_id);
- if(script != null) {
- setScriptVar("player", player);
- script.callEvent("quest_term", script);
- quest.term(script, player);
- msg.prefix(player, "§dQuest", "Quest termed.");
- }
- }
- }
- modTimer(-50);
- entity.teleport(player, location);
- player.setHeadName(player);
-
- if(world.isGamesName(to_world_name)) {
- player.clearInventory(player);
- inv = player.getInv(player);
- inv.setItem(inv, 0, item.create("COMPASS", 1, null, null));
- }
- player.setTabName(player);
- return true;
- }
- function playerdata.getSurvival(player_or_id) {
- player_id = player.getValidId(player_or_id);
- if(player_id == null) {
- msg.dev(string.concat("invalid player_id ", player_id, " on playerdata.getSurvival"));
- return;
- }
- map = getScriptVar("survival_data");
- config = map.get(map, player_id);
- if(config == null) {
- playerdata.load(player_id, map, "survival_data");
- config = map.get(map, player_id);
- }
- return config;
- }
- function playerdata.getGames(player_or_id) {
- player_id = player.getValidId(player_or_id);
- if(player_id == null) {
- msg.dev(string.concat("invalid player_id ", player_id, " on playerdata.getGames"));
- return;
- }
- map = getScriptVar("games_data");
- config = map.get(map, player_id);
- if(config == null) {
- playerdata.load(player_id, map, "games_data");
- config = map.get(map, player_id);
- }
- return config;
- }
- function playerdata.load(player_or_id, map, name) {
- player_id = player.getValidId(player_or_id);
- if(player_id == null) {
- msg.dev(string.concat("invalid player_id ", player_id, " on playerdata.load"));
- return;
- }
- config = map.get(map, player_id);
- if(config == null) {
- config = config.new(string.concat("scripts/configs/player_data/", name), player_id);
- if(config.exists(config)) {
- config.load(config);
- }
- map.add(map, player_id, config);
- }
- }
- function player.getValidId(player_or_id) {
- if(isPlayer(player_or_id)) {
- return player.getId(player_or_id);
- }
- if(isDouble(player_or_id)) {
- if(player.getNameFromId(player_or_id) != null) {
- return player_or_id;
- }
- }
- return null;
- }
- function player.getValid(player_or_id) {
- if(isPlayer(player_or_id)) {
- return player_or_id;
- }
- player = player.get(player.getUuidFromId(player_or_id));
- if(player == null) {
- return null;
- }
- return player;
- }
- //--------------------------------------------------
- //Msg-Utils
- //--------------------------------------------------
- function getMessage(text_or_string) {
- if(isString(text_or_string)) {
- message = getMessageFromString(text_or_string);
- } else {
- message = text_or_string;
- }
- return message;
- }
- function getMessageFromString(string) {
- string = string.replace(string, "&", "§");
- message = string.getTextWithLink(string);
- return message;
- }
- function msg.action(receiver, text_or_string) {
- player.action(receiver, getMessage(text_or_string));
- }
- function msg.string(receiver, string) {
- msg(receiver, text.new(string));
- }
- function msg.prefix(receiver, prefix, text_or_string) {
- msg(receiver, text.merge(text.new(string.concat(string.getPrefix(prefix), " ")), getMessage(text_or_string)));
- }
- function msg.online(prefix, text_or_string) {
- msg.prefix("online", prefix, text_or_string);
- }
- function msg.quest(player, speaker, line_now, line_max, string) {
- msg.string(player, string.concat("[§b", string.number(line_now), "§r/§b", string.number(line_max), "§r] §a", speaker, " §r| ", string.concat("§e", string)));
- }
- function msg.chat(player, text_or_string) {
- nickname = player.getNickName(player);
- rank = getRank(player);
- colorcode = string.subString(rank, 0, 2);
- if(player.isLive(player)) {
- live_tag = "§dLive §f| ";
- } else {
- live_tag = "";
- }
- online_list = players.toList();
- iter = iterator(online_list);
- while(hasNext(iter)) {
- p = next(iter);
- if(player.hasMinigame(p) && player.isMuted(p)) {
- continue;
- }
- msg(p, text.merge(text.new("<"), text.new(live_tag), string.getHoverText(string.concat(colorcode, nickname), rank), text.new("§r> §r"), getMessage(text_or_string)));
- }
- msg("SERVER", text.merge(text.new("<"), text.new(live_tag), string.getHoverText(string.concat(colorcode, nickname), rank), text.new("§r> §r"), getMessage(text_or_string)));
- }
- function msg.send(from_player, to_name, prefix, string_message, send_mail) {
- p = read.player(to_name);
- if(p == null) {
- if(send_mail) {
- mail.send(player.getName(from_player), to_name, string_message);
- }
- } else {
- msg.prefix(p, prefix, string_message);
- }
- }
- function msg.team(from, text_or_string) {
- if(isString(from)) {
- from_name = from;
- } else {
- from_name = player.getName(from);
- }
- pre_text = text.new(string.concat("§c", from_name, "§r: "));
- message = getMessage(text_or_string);
- online_list = players.toList();
- iter = iterator(online_list);
- while(hasNext(iter)) {
- p = next(iter);
- if(perm.has("isTeam", p)) {
- if(player.isLive(p)) {
- msg.prefix(p, "§4Team", text.merge(pre_text, text.hover(text.new("§7§oHidden"), message)));
- } else {
- msg.prefix(p, "§4Team", text.merge(pre_text, message));
- }
- }
- }
- msg.prefix("SERVER", "§4Team", text.merge(pre_text, message));
- }
- function msg.radius(prefix, text_or_string, location, radius) {
- list = players.near(location, radius);
- iter = iterator(list);
- while(hasNext(iter)) {
- msg.prefix(next(iter), prefix, text_or_string);
- }
- }
- function msg.world(world, text_or_string) {
- if(world == null) {
- return;
- }
- world_list = world.getPlayers(world);
- iter = iterator(world_list);
- while(hasNext(iter)) {
- msg(next(iter), getMessage(text_or_string));
- }
- }
- function msg.survival(text_or_string) {
- msg.world(world.getOverWorld(), text_or_string);
- msg.world(world.getTheEnd(), text_or_string);
- msg.world(world.getTheNether(), text_or_string);
- }
- function msg.creative(text_or_string) {
- msg.world(world.getCreative(), text_or_string);
- }
- function msg.games(text_or_string) {
- msg.world(world.getGames(), text_or_string);
- }
- //--------------------------------------------------
- //Material-Utils
- //--------------------------------------------------
- function isMaterial(anything) {
- return string.class(anything) == "Material";
- }
- function material.getAir() {
- return material.get("AIR");
- }
- function material.equals(type, type_string) {
- return type == material.get(type_string);
- }
- //--------------------------------------------------
- //Item-Utils
- //--------------------------------------------------
- function item.isType(item, type_string) {
- return item.getType(item) == material.get(type_string);
- }
- function isSameItem(itemstack_1, itemstack_2) {
- itemstack_1 = item.clone(itemstack_1);
- itemstack_2 = item.clone(itemstack_2);
- item.setAmount(itemstack_1, 1);
- item.setAmount(itemstack_2, 1);
- return itemstack_1 == itemstack_2;
- }
- function isItemstack(anything) {
- type = string.class(anything);
- return type == "ItemStack" || type == "CraftItemStack";
- }
- function item.isAir(itemstack) {
- if(itemstack == null) {
- return true;
- }
- return item.getType(itemstack) == material.getAir();
- }
- //--------------------------------------------------
- //Customitem-Utils
- //--------------------------------------------------
- function customitem.getNameForModel(model) {
- model = string.toUpperCase(model);
- custom_item_names = map.new();
- map.add(custom_item_names, "AMBER", "Amber");
- map.add(custom_item_names, "SAPPHIRE", "Sapphire");
- map.add(custom_item_names, "RUBY", "Ruby");
- map.add(custom_item_names, "GOLD_COIN", "Gold Coin");
- map.add(custom_item_names, "SILVER_COIN", "Silver Coin");
- map.add(custom_item_names, "COPPER_COIN", "Copper Coin");
- map.add(custom_item_names, "ARROW_DOWN", "Down Arrow");
- map.add(custom_item_names, "ARROW_LEFT", "Left Arrow");
- map.add(custom_item_names, "ARROW_RIGHT", "Right Arrow");
- map.add(custom_item_names, "ARROW_UP", "Up Arrow");
- map.add(custom_item_names, "CHECK_GREEN", "Green Check");
- map.add(custom_item_names, "CHECK_RED", "Red Check");
- map.add(custom_item_names, "DIGIT_0", "Digit 0");
- map.add(custom_item_names, "DIGIT_1", "Digit 1");
- map.add(custom_item_names, "DIGIT_2", "Digit 2");
- map.add(custom_item_names, "DIGIT_3", "Digit 3");
- map.add(custom_item_names, "DIGIT_4", "Digit 4");
- map.add(custom_item_names, "DIGIT_5", "Digit 5");
- map.add(custom_item_names, "DIGIT_6", "Digit 6");
- map.add(custom_item_names, "DIGIT_7", "Digit 7");
- map.add(custom_item_names, "DIGIT_8", "Digit 8");
- map.add(custom_item_names, "DIGIT_9", "Digit 9");
- map.add(custom_item_names, "PLUS_GREEN", "Green Plus");
- map.add(custom_item_names, "PLUS_RED", "Red Plus");
- map.add(custom_item_names, "REFRESH_GREEN", "Green Refresh");
- map.add(custom_item_names, "REFRESH_RED", "Red Refresh");
- map.add(custom_item_names, "RETURN_GREEN", "Green Return");
- map.add(custom_item_names, "RETURN_RED", "Red Return");
- map.add(custom_item_names, "CROSS_GREEN", "Green Cross");
- map.add(custom_item_names, "CROSS_RED", "Red Cross");
- map.add(custom_item_names, "GEAR", "Gear");
- map.add(custom_item_names, "MINUS_GREEN", "Green Minus");
- map.add(custom_item_names, "MINUS_RED", "Red Minus");
- map.add(custom_item_names, "SCROLL", "Scroll");
- return map.get(custom_item_names, model);
- }
- // do not use this command in other scripts
- function customitem.get(model) {
- name = customitem.getNameForModel(model);
- model = string.toLowerCase(model);
- return read.item(string.concat("{components:{'minecraft:custom_name':'\"§f", name, "\"','minecraft:item_model':'minecraft:", model, "'},count:1,id:'minecraft:command_block'}"));
- }
- function customitem.getAll() {
- customitems = list.new();
- list.add(customitems, customitem.getAmber());
- list.add(customitems, customitem.getSapphire());
- list.add(customitems, customitem.getRuby());
- list.add(customitems, customitem.getGoldCoin());
- list.add(customitems, customitem.getSilverCoin());
- list.add(customitems, customitem.getCopperCoin());
- list.add(customitems, customitem.getDownArrow());
- list.add(customitems, customitem.getLeftArrow());
- list.add(customitems, customitem.getRightArrow());
- list.add(customitems, customitem.getUpArrow());
- list.add(customitems, customitem.getGreenCheck());
- list.add(customitems, customitem.getRedCheck());
- list.add(customitems, customitem.getDigit0());
- list.add(customitems, customitem.getDigit1());
- list.add(customitems, customitem.getDigit2());
- list.add(customitems, customitem.getDigit3());
- list.add(customitems, customitem.getDigit4());
- list.add(customitems, customitem.getDigit5());
- list.add(customitems, customitem.getDigit6());
- list.add(customitems, customitem.getDigit7());
- list.add(customitems, customitem.getDigit8());
- list.add(customitems, customitem.getDigit9());
- list.add(customitems, customitem.getGreenPlus());
- list.add(customitems, customitem.getRedPlus());
- list.add(customitems, customitem.getGreenRefresh());
- list.add(customitems, customitem.getRedRefresh());
- list.add(customitems, customitem.getGreenReturn());
- list.add(customitems, customitem.getRedReturn());
- list.add(customitems, customitem.getGreenCross());
- list.add(customitems, customitem.getRedCross());
- list.add(customitems, customitem.getGear());
- list.add(customitems, customitem.getGreenMinus());
- list.add(customitems, customitem.getRedMinus());
- list.add(customitems, customitem.getScroll());
- return customitems;
- }
- function customitem.getAmber() {
- return customitem.get("AMBER");
- }
- function customitem.getSapphire() {
- return customitem.get("SAPPHIRE");
- }
- function customitem.getRuby() {
- return customitem.get("RUBY");
- }
- function customitem.getGoldCoin() {
- return customitem.get("GOLD_COIN");
- }
- function customitem.getSilverCoin() {
- return customitem.get("SILVER_COIN");
- }
- function customitem.getCopperCoin() {
- return customitem.get("COPPER_COIN");
- }
- function customitem.getDownArrow() {
- return customitem.get("ARROW_DOWN");
- }
- function customitem.getLeftArrow() {
- return customitem.get("ARROW_LEFT");
- }
- function customitem.getRightArrow() {
- return customitem.get("ARROW_RIGHT");
- }
- function customitem.getUpArrow() {
- return customitem.get("ARROW_UP");
- }
- function customitem.getGreenCheck() {
- return customitem.get("CHECK_GREEN");
- }
- function customitem.getRedCheck() {
- return customitem.get("CHECK_RED");
- }
- function customitem.getDigit0() {
- return customitem.get("DIGIT_0");
- }
- function customitem.getDigit1() {
- return customitem.get("DIGIT_1");
- }
- function customitem.getDigit2() {
- return customitem.get("DIGIT_2");
- }
- function customitem.getDigit3() {
- return customitem.get("DIGIT_3");
- }
- function customitem.getDigit4() {
- return customitem.get("DIGIT_4");
- }
- function customitem.getDigit5() {
- return customitem.get("DIGIT_5");
- }
- function customitem.getDigit6() {
- return customitem.get("DIGIT_6");
- }
- function customitem.getDigit7() {
- return customitem.get("DIGIT_7");
- }
- function customitem.getDigit8() {
- return customitem.get("DIGIT_8");
- }
- function customitem.getDigit9() {
- return customitem.get("DIGIT_9");
- }
- function customitem.getGreenPlus() {
- return customitem.get("PLUS_GREEN");
- }
- function customitem.getRedPlus() {
- return customitem.get("PLUS_RED");
- }
- function customitem.getGreenRefresh() {
- return customitem.get("REFRESH_GREEN");
- }
- function customitem.getRedRefresh() {
- return customitem.get("REFRESH_RED");
- }
- function customitem.getGreenReturn() {
- return customitem.get("RETURN_GREEN");
- }
- function customitem.getRedReturn() {
- return customitem.get("RETURN_RED");
- }
- function customitem.getGreenCross() {
- return customitem.get("CROSS_GREEN");
- }
- function customitem.getRedCross() {
- return customitem.get("CROSS_RED");
- }
- function customitem.getGear() {
- return customitem.get("GEAR");
- }
- function customitem.getGreenMinus() {
- return customitem.get("MINUS_GREEN");
- }
- function customitem.getRedMinus() {
- return customitem.get("MINUS_RED");
- }
- function customitem.getScroll() {
- return customitem.get("SCROLL");
- }
- function customitem.isType(item, custom) {
- nbt = string.item(item);
- custom = string.toLowerCase(custom);
- custom = string.concat("\"minecraft:item_model\":\"minecraft:", custom);
- return string.contains(nbt, custom);
- }
- function customitem.create(type, amount, name, wusi) {
- //wusi: lore_list or lore_string
- item = customitem.get(type);
- if(name != null) {
- item.setName(item, text.new(name));
- }
- item.setAmount(item, amount);
- if(wusi != null) {
- if(isString(wusi)) {
- lore_list = list.new();
- list.add(lore_list, text.new(wusi));
- item.setLore(item, lore_list);
- } else {
- item.setLore(item, wusi);
- }
- }
- return item;
- }
- function customitem.isAmber(item) {
- return customitem.isType(item, "AMBER");
- }
- function customitem.isSapphire(item) {
- return customitem.isType(item, "SAPPHIRE");
- }
- function customitem.isRuby(item) {
- return customitem.isType(item, "RUBY");
- }
- function customitem.isGoldCoin(item) {
- return customitem.isType(item, "GOLD_COIN");
- }
- function customitem.isSilverCoin(item) {
- return customitem.isType(item, "SILVER_COIN");
- }
- function customitem.isCopperCoin(item) {
- return customitem.isType(item, "COPPER_COIN");
- }
- function customitem.isRedReturn(item) {
- return customitem.isType(item, "RETURN_RED");
- }
- function customitem.isGreenReturn(item) {
- return customitem.isType(item, "RETURN_GREEN");
- }
- function customitem.isRedRefresh(item) {
- return customitem.isType(item, "REFRESH_RED");
- }
- function customitem.isGreenRefresh(item) {
- return customitem.isType(item, "REFRESH_GREEN");
- }
- function customitem.isRedCross(item) {
- return customitem.isType(item, "CROSS_RED");
- }
- function customitem.isGreenCross(item) {
- return customitem.isType(item, "CROSS_GREEN");
- }
- function customitem.isRedCheck(item) {
- return customitem.isType(item, "CHECK_GREEN");
- }
- function customitem.isGreenCheck(item) {
- return customitem.isType(item, "CHECK_RED");
- }
- function customitem.isUpArrow(item) {
- return customitem.isType(item, "ARROW_UP");
- }
- function customitem.isDownArrow(item) {
- return customitem.isType(item, "ARROW_DOWN");
- }
- function customitem.isLeftArrow(item) {
- return customitem.isType(item, "ARROW_LEFT");
- }
- function customitem.isRightArrow(item) {
- return customitem.isType(item, "ARROW_RIGHT");
- }
- function customitem.isGear(item) {
- return customitem.isType(item, "GEAR");
- }
- function customitem.isDigit(item) {
- return customitem.isType(item, "DIGIT");
- }
- function item.create(type, amount, name, wusi) {
- //wusi: lore_list or lore_string
- item = item.new(material.get(type), amount);
- if(name != null) {
- item.setName(item, text.new(name));
- }
- if(wusi != null) {
- if(isString(wusi)) {
- lore_list = list.new();
- list.add(lore_list, text.new(wusi));
- item.setLore(item, lore_list);
- } else {
- item.setLore(item, wusi);
- }
- }
- return item;
- }
- function item.createLore(string) {
- lore = list.new();
- list.add(lore, text.new(string));
- return lore;
- }
- function item.addLore(item, string) {
- lore = item.getLore(item);
- if(lore == null) {
- lore = list.new();
- }
- list.add(lore, text.new(string));
- item.setLore(item, lore);
- }
- function item.getAir() {
- return item.new(material.get("AIR"));
- }
- function item.getAirString() {
- return "{id:\"minecraft:air\",Count:1b}";
- }
- function drops.containsMaterial(drops_list, material) {
- for(i = 0; i < list.getSize(drops_list); i++) {
- item_entity = list.getIndex(drops_list, i);
- item = item.entity.get(item_entity);
- item_type = item.getType(item);
- if(item_type == material) {
- return true;
- }
- }
- return false;
- }
- //--------------------------------------------------
- //Entity-Utils
- //--------------------------------------------------
- function entity.isArmorstand(entity) {
- if(entity == null) {
- return false;
- }
- return entity.getType(entity) == "armor_stand";
- }
- //--------------------------------------------------
- //Player-Utils
- //--------------------------------------------------
- function player.hasBypass(player) {
- return perm.has("plot.bypass", player);
- }
- function player.clearInventory(player) {
- inv = player.getInv(player);
- inv.clear(inv);
- }
- function player.toggleFly(player) {
- new_state = !player.hasFly(player);
- player.setFly(player, new_state);
- return new_state;
- }
- function player.canTeleport(player) {
- if(player.hasMinigame(player)) {
- return false;
- }
- if(player.isOnAdventure(player)) {
- return false;
- }
- return true;
- }
- function player.hasClearInventory(player) {
- air = item.getAir();
- inv = player.getInv(player);
- for(slot = 0; slot < 36; slot++) {
- if(item.getType(inv.getItem(inv, slot)) != air) {
- return false;
- }
- }
- if(item.getType(living.getEquip(player, read.slot("HEAD"))) != air) {
- return false;
- }
- if(item.getType(living.getEquip(player, read.slot("CHEST"))) != air) {
- return false;
- }
- if(item.getType(living.getEquip(player, read.slot("LEGS"))) != air) {
- return false;
- }
- if(item.getType(living.getEquip(player, read.slot("FEET"))) != air) {
- return false;
- }
- if(item.getType(living.getOffHand(player)) != air) {
- return false;
- }
- return true;
- }
- function player.getJoinMessage(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- temp = config.getString(config, "message.join", "null");
- if(temp == "null") {
- return null;
- }
- return temp;
- }
- function player.setJoinMessage(player_or_id, message) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "message.join", message);
- config.saveAsync(config);
- }
- function player.getLeaveMessage(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- temp = config.getString(config, "message.leave", "null");
- if(temp == "null") {
- return null;
- }
- return temp;
- }
- function player.setLeaveMessage(player_or_id, message) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "message.leave", message);
- config.saveAsync(config);
- }
- function player.getDeathMessage(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- temp = config.getString(config, "message.death", "null");
- if(temp == "null") {
- return null;
- }
- return temp;
- }
- function player.setDeathMessage(player_or_id, message) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "message.death", message);
- config.saveAsync(config);
- }
- function player.usesCustomMessage(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "message.use", true);
- }
- function player.activateCustomMessage(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "message.use", boolean);
- config.saveAsync(config);
- }
- function player.setLoggedIp(player_or_id, ip) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "ip", ip);
- config.saveAsync(config);
- }
- function player.getLoggedIp(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getString(config, "ip", "-");
- }
- function player.resetDeathLoc(player) {
- config = playerdata.getSurvival(player);
- config.set(config, "deathloc", "null");
- config.saveAsync(config);
- }
- function player.setDeathLoc(player) {
- config = playerdata.getSurvival(player);
- config.set(config, "deathloc", string.location(entity.getLocation(player)));
- config.saveAsync(config);
- }
- function player.getDeathLoc(player) {
- config = playerdata.getSurvival(player);
- loc = config.getString(config, "deathloc", "null");
- if(loc == "null") {
- return null;
- }
- return read.location(loc);
- }
- function player.isLive(player) {
- player_uuid = player.getUuid(player);
- live_set = getScriptVar("live_set");
- return set.contains(live_set, player_uuid);
- }
- function player.setLive(player, boolean) {
- player_uuid = player.getUuid(player);
- live_set = getScriptVar("live_set");
- if(boolean) {
- set.add(live_set, player_uuid);
- } else {
- set.remove(live_set, player_uuid);
- }
- }
- function player.getFullName(player) {
- nickname = player.getNickname(player);
- if(player.isNicked(player)) {
- full_name = string.concat("[§3User§r] ", nickname);
- } else {
- full_name = string.concat("[", getRank(player), "§r] ", nickname);
- }
- return full_name;
- }
- function player.setTabName(player) {
- nickname = player.getNickname(player);
- rank = getRank(player);
- if(string.startswith(rank, "§", 0)) {
- colorcode = string.subString(rank, 0, 2);
- tab_name = string.concat(colorcode, nickname);
- } else {
- tab_name = nickname;
- }
- if(player.isAfk(player)) {
- tab_name = string.concat(tab_name, " §5§o[Afk]");
- }
- if(player.isLive(player)) {
- tab_name = string.concat(tab_name, " §f[§dLive§f]");
- }
- player.setDisplayName(player, text.new(tab_name));
- }
- function player.removeItemNbt(player, itemstack) { //Might be deprecated
- //Make a copy
- item_type = item.getType(itemstack);
- amount = item.getAmount(itemstack);
- my_item = item.new(item_type, amount);
- //Loop the inventory
- inv = player.getInv(player);
- for(slot = 0; slot < inv.getSize(inv); slot++) {
- item = inv.getItem(inv, slot);
- if(item == null) {
- continue;
- }
- if(item.getType(item) == item_type) {
- diff = amount - item.getAmount(item);
- if(diff > 0) {
- amount = diff;
- item.setAmount(item, 0);
- } else {
- item.setAmount(item, math.abs(diff));
- air = item.getAir();
- item.setAmount(air, 0);
- return air;
- }
- }
- }
- item.setAmount(my_item, amount);
- return my_item;
- }
- function player.removeItemTag(player, tag, amount) {
- air = item.getAir();
- inv = player.getInv(player);
- for(slot = 0; slot < inv.getSize(inv); slot++) {
- item = inv.getItem(inv, slot);
- if(item == null) {
- continue;
- }
- if(item.hasTag(item, tag)) {
- diff = amount - item.getAmount(item);
- if(diff > 0) {
- item.setAmount(item, 0);
- amount = diff;
- } else {
- item.setAmount(item, math.abs(diff));
- amount = 0;
- break;
- }
- }
- }
- item.setAmount(air, amount);
- return air;
- }
- function player.setSpeed(player, speed) {
- speed = 4/5/9 * speed + 1/9;
- player.setWalkSpeed(player, speed);
- player.setFlySpeed(player, speed / 2);
- }
- function player.hasBigPlotCreated(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "plot.big", false);
- }
- function player.setBigPlotCreated(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "plot.big", boolean);
- config.saveAsync(config);
- }
- function player.hasPlotRaised(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "plot.raised", false);
- }
- function player.setPlotRaised(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "plot.raised", boolean);
- config.saveAsync(config);
- }
- function player.usedHisFreePlot(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "plot.usedFree", false);
- }
- function player.setUsedFreePlot(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "plot.usedFree", boolean);
- config.saveAsync(config);
- }
- function player.activateSitting(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "sitting", boolean);
- config.saveAsync(config);
- }
- function player.hasSittingActivated(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "sitting", true);
- }
- function player.acceptTpaRequests(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "tptoggle", boolean);
- config.saveAsync(config);
- }
- function player.doesAcceptTpaRequests(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "tptoggle", true);
- }
- function player.getBackPos(player) {
- config = playerdata.getSurvival(player);
- location = config.getString(config, "backpos", "null");
- if(location == "null") {
- return null;
- }
- return read.location(location);
- }
- function player.setBackPos(player) {
- config = playerdata.getSurvival(player);
- config.set(config, "backpos", string.location(entity.getLocation(player)));
- config.saveAsync(config);
- }
- function player.setBackPosLoc(player, location) {
- config = playerdata.getSurvival(player);
- config.set(config, "backpos", string.location(location));
- config.saveAsync(config);
- }
- function player.clearBackPos(player) {
- config = playerdata.getSurvival(player);
- config.set(config, "backpos", "null");
- config.saveAsync(config);
- }
- function entity.getFromDamageSource(damage_source) {
- entity = damage.getImmediateSource(damage_source);
- if(entity == null) {
- return damage.getTrueSource(damage_source);
- }
- return entity;
- }
- function player.getFromDamageSource(damage_source) {
- entity = damage.getImmediateSource(damage_source);
- if(isPlayer(entity)) {
- return entity;
- }
- entity = damage.getTrueSource(damage_source);
- if(isPlayer(entity)) {
- return entity;
- }
- return null;
- }
- function player.getJoins(player_or_id) {
- if(isPlayer(player_or_id)) {
- player_id = player.getId(player_or_id);
- } else {
- player_id = player_or_id;
- }
- stmt = databank.prepare("SELECT COUNT(join_time) FROM playtime WHERE player_id = ?;");
- databank.setInt(stmt, 1, player_id);
- result = databank.execute(stmt);
- if(databank.next(result)) {
- amount = databank.getLong(result, 1);
- }
- databank.close(result);
- databank.close(stmt);
- return amount;
- }
- function player.getTotalPlaytime(player_or_id) {
- if(isPlayer(player_or_id)) {
- player_id = player.getId(player_or_id);
- } else {
- player_id = player_or_id;
- }
- //Online seit
- since_minutes = 0;
- if(isOnline(player.getNameFromId(player_id))) {
- stmt = databank.prepare("SELECT join_time FROM playtime WHERE player_id = ? AND leave_time IS NULL;");
- databank.setInt(stmt, 1, player_id);
- result = databank.execute(stmt);
- while(databank.next(result)) {
- since_minutes = (time.getMillis() - databank.getLong(result, 1)) / 1000 / 60;
- }
- databank.close(result);
- databank.close(stmt);
- }
- //Spielzeit gesamt
- stmt2 = databank.prepare("SELECT SUM(leave_time - join_time) FROM playtime WHERE player_id = ?;");
- databank.setInt(stmt2, 1, player_id);
- result = databank.execute(stmt2);
- while(databank.next(result)) {
- minutes = databank.getLong(result, 1) / 1000 / 60 + since_minutes;
- }
- databank.close(result);
- databank.close(stmt2);
- return minutes;
- }
- function player.hasInvIgnore(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "invignore", false);
- }
- function player.invIgnore(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "invignore", boolean);
- config.saveAsync(config);
- }
- function player.getClanId(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getDouble(config, "clan_id", -1);
- }
- function player.setClanId(player_or_id, clan_id) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "clan_id", clan_id);
- config.saveAsync(config);
- }
- function player.getClanRole(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- temp = config.getString(config, "clan_role", "null");
- if(temp == "null") {
- return null;
- }
- return temp;
- }
- function player.setClanRole(player_or_id, clan_id) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "clan_role", clan_id);
- config.saveAsync(config);
- }
- function player.isInClan(player_or_id) {
- return player.getClanId(player_or_id) >= 0;
- }
- function player.isClanLeader(player_or_id) {
- return player.getClanRole(player_or_id) == "leader";
- }
- function player.isClanMod(player_or_id) {
- return player.getClanRole(player_or_id) == "mod";
- }
- function player.isClanMember(player_or_id) {
- return player.getClanRole(player_or_id) == "member";
- }
- function player.isSameClan(player_or_id_1, player_or_id_2) {
- id_1 = player.getClanId(player_or_id_1);
- id_2 = player.getClanId(player_or_id_2);
- if(id_1 < 0 || id_2 < 0) {
- return false;
- }
- return id_1 == id_2;
- }
- function player.setHeadName(player) {
- nickname = player.getNickname(player);
- clan_string = "";
- if(player.isInClan(player)) {
- clan_id = player.getClanId(player);
- clan_string = string.concat(" [§6", clan.getTag(clan_id), "§r]");
- }
- live_string = "";
- if(player.isLive(player)) {
- live_string = "§f[§dLive§f] ";
- }
- entity.setName(player, text.new(string.concat(live_string, nickname, clan_string)));
- }
- function player.setAIChallengeAmounts(player_or_id, amount) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "cha.ai.amount", amount);
- config.saveAsync(config);
- }
- function player.getAIhallengeAmounts(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getDouble(config, "cha.ai.amount", 0);
- }
- function player.setAEChallengeAmounts(player_or_id, amount) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "cha.ae.amount", amount);
- config.saveAsync(config);
- }
- function player.getAEChallengeAmounts(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getDouble(config, "cha.ae.amount", 0);
- }
- function player.setADTChallengeAmounts(player_or_id, amount) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "cha.dtype.amount", amount);
- config.saveAsync(config);
- }
- function player.getADTChallengeAmounts(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getDouble(config, "cha.dtype.amount", 0);
- }
- function player.setAdventureAmounts(player_or_id, amount) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "adventures", amount);
- config.saveAsync(config);
- }
- function player.getAdventureAmounts(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getDouble(config, "adventures", 0);
- }
- function player.isOnAdventure(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "onadventure", false);
- }
- function player.setAdventure(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "onadventure", boolean);
- config.saveAsync(config);
- }
- function player.getAdventureStart(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- location = config.getString(config, "adventureloc", "null");
- if(location == "null") {
- return world.getServerSpawn();
- }
- return read.location(location);
- }
- function player.setAdventureStart(player_or_id, location) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "adventureloc", string.location(location));
- config.saveAsync(config);
- }
- function player.isMuted(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "muted", false);
- }
- function player.mute(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "muted", boolean);
- config.saveAsync(config);
- }
- function player.isGameMuted(player_or_id) {
- config = playerdata.getGames(player_or_id);
- return config.getBool(config, "game_muted", false);
- }
- function player.gameMute(player_or_id, boolean) {
- config = playerdata.getGames(player_or_id);
- config.set(config, "game_muted", boolean);
- config.saveAsync(config);
- }
- function player.getSilentJoin(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "silentjoin", false);
- }
- function player.setSilentJoin(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "silentjoin", boolean);
- config.saveAsync(config);
- }
- function player.getAutoCloseDoor(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "door_auto_close", true);
- }
- function player.setAutoCloseDoor(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "door_auto_close", boolean);
- config.saveAsync(config);
- }
- function player.getNoPetDamage(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "pet_damage", true);
- }
- function player.setNoPetDamage(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "pet_damage", boolean);
- config.saveAsync(config);
- }
- function player.getTipLoop(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "tip_loop", true);
- }
- function player.setTipLoop(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "tip_loop", boolean);
- config.saveAsync(config);
- }
- function player.setVoteStreak(player_or_id, millis) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "votestreak", millis);
- config.saveAsync(config);
- }
- function player.getVoteStreak(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getDouble(config, "votestreak", 0);
- }
- function player.setLastVoteTime(player_or_id, millis) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "lastvotetime", millis);
- config.saveAsync(config);
- }
- function player.getLastVoteTime(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getDouble(config, "lastvotetime", 0);
- }
- function player.setVotePoints(player_or_id, amount) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "votepoints", amount);
- config.saveAsync(config);
- }
- function player.getVotePoints(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getDouble(config, "votepoints", 0);
- }
- function player.addVotePoints(player_or_id, amount) {
- config = playerdata.getSurvival(player_or_id);
- points = config.getDouble(config, "votepoints", 0) + amount;
- config.set(config, "votepoints", points);
- config.saveAsync(config);
- }
- function player.isFirstJoin(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "firstjoin", true);
- }
- function player.setFirstJoin(player_or_id, boolean) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "firstjoin", !boolean);
- config.saveAsync(config);
- }
- function player.getShowcoords(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "showcoords", true);
- }
- function player.setShowcoords(player_or_id, bool) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "showcoords", bool);
- config.saveAsync(config);
- }
- function player.getFirstJoin(player_or_id) {
- if(isPlayer(player_or_id)) {
- player_id = player.getId(player_or_id);
- } else {
- player_id = player_or_id;
- }
- stmt = databank.prepare("SELECT MIN(join_time) FROM playtime WHERE player_id = ?;");
- databank.setInt(stmt, 1, player_id);
- result = databank.execute(stmt);
- if(databank.next(result)) {
- time = databank.getLong(result, 1);
- }
- databank.close(result);
- databank.close(stmt);
- return time;
- }
- function player.getLastJoin(player_or_id) {
- if(isPlayer(player_or_id)) {
- player_id = player.getId(player_or_id);
- } else {
- player_id = player_or_id;
- }
- stmt = databank.prepare("SELECT MAX(join_time) FROM playtime WHERE player_id = ?;");
- databank.setInt(stmt, 1, player_id);
- result = databank.execute(stmt);
- if(databank.next(result)) {
- time = databank.getLong(result, 1);
- }
- databank.close(result);
- databank.close(stmt);
- return time;
- }
- function player.blockCommands(player) {
- list = getScriptVar("block_commands_list");
- list.add(list, player.getUuid(player));
- }
- function player.unblockCommands(player) {
- list = getScriptVar("block_commands_list");
- player_uuid = player.getUuid(player);
- while(list.contains(list, player_uuid)) {
- list.remove(list, player_uuid);
- }
- }
- function player.isCommandBlocked(player) {
- list = getScriptVar("block_commands_list");
- return list.contains(list, player.getUuid(player));
- }
- function player.checkHandForType(player, item_type) {
- return item.getType(living.getHand(player)) == item_type;
- }
- function player.checkHandsForItem(player, item_or_type) {
- if(string.class(item_or_type) != "String") {
- item_or_type = item.getType(item_or_type);
- }
- hand = living.getHand(player);
- if(item.getType(hand) == item_or_type) {
- return true;
- }
- offhand = living.getOffHand(player);
- return item.getType(offhand) == item_or_type;
- }
- function player.checkHandsForTag(player, tag) {
- hand = living.getHand(player);
- if(item.hasTag(hand, tag)) {
- return true;
- }
- offhand = living.getOffHand(player);
- return item.hasTag(offhand, tag);
- }
- function player.hideOnline(player) {
- list = players.toList();
- iter = iterator(list);
- while(hasNext(iter)) {
- p = next(iter);
- player.hide(p, player);
- }
- }
- function player.showOnline(player) {
- list = players.toList();
- iter = iterator(list);
- while(hasNext(iter)) {
- p = next(iter);
- player.show(p, player);
- }
- }
- //--------------------------------------------------
- //Chestshop-Utils
- //--------------------------------------------------
- function shop.getOwner(sign_block) {
- owner_id = read.number(sign.getString(sign_block, "FRONT", 3));
- if(owner_id == null) {
- return null;
- }
- return owner_id;
- }
- function shop.isOwner(player, sign_block) {
- if(player.hasBypass(player)) {
- return true;
- }
- owner_id = shop.getOwner(sign_block);
- if(owner_id == null) {
- return false;
- }
- owner_name = player.getNameFromId(owner_id);
- if(owner_name == null) {
- return false;
- }
- return owner_id == player.getId(player);
- }
- //--------------------------------------------------
- //Block-Utils
- //--------------------------------------------------
- function block.isChest(block) {
- return block.isType(block, "minecraft:chest");
- }
- function block.isWallSign(block) {
- if(block == null) {
- return false;
- }
- return block.hasTag(block, block.getTag("minecraft:wall_signs"));
- }
- function sign.getString(block, side, row) {
- return string.text(block.getSign(block, side, row));
- }
- function sign.setString(block, side, row, string) {
- block.setSign(block, side, row, text.new(string));
- }
- function block.isType(block, type_string) {
- return block.getType(block) == material.get(type_string);
- }
- function block.isAir(block) {
- type = block.getType(block);
- return type == material.getAir() || type == material.get("CAVE_AIR");
- }
- function block.mod(block, x, y, z) {
- return block.get(loc.mod(block.getLocation(block), x, y, z));
- }
- function block.gotWater(block) {
- if(block.canHaveWater(block)) {
- return block.isWaterlogged(block);
- }
- return false;
- }
- function block.clearInventory(block) {
- inv = block.getInventory(block);
- inv.clear(inv);
- }
- //--------------------------------------------------
- //Money-Utils
- //--------------------------------------------------
- function hasEnoughMoney(player_or_id, price) {
- return money.get(player_or_id) >= price;
- }
- function money.get(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getDouble(config, "money", 0);
- }
- function money.set(player_or_id, money) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "money", money);
- config.saveAsync(config);
- player = player.getValid(player_or_id);
- if(player == null) {
- return;
- }
- money.display(player, money);
- }
- function money.getBoostFactor() {
- return getScriptVar("money_factor");
- }
- function money.setBoostFactor(factor) {
- setScriptVar("money_factor", factor);
- }
- function money.addBoost(player_or_id, money) {
- money *= money.getBoostFactor();
- player = player.getValid(player_or_id);
- if(player == null) {
- return;
- }
- if(money.getBoostFactor() > 1) {
- money.popUp(player, money, true);
- }
- money.add(player, money);
- }
- function money.add(player_or_id, money) {
- if(money == 0) {
- return;
- }
- config = playerdata.getSurvival(player_or_id);
- new_money = config.getDouble(config, "money", 0) + money;
- config.set(config, "money", new_money);
- config.saveAsync(config);
- player = player.getValid(player_or_id);
- if(player == null) {
- return;
- }
- money.display(player, new_money);
- money.popUp(player, money, false);
- }
- function money.sub(player_or_id, money) {
- if(money == 0) {
- return;
- }
- config = playerdata.getSurvival(player_or_id);
- new_money = config.getDouble(config, "money", 0) - money;
- config.set(config, "money", new_money);
- config.saveAsync(config);
- player = player.getValid(player_or_id);
- if(player == null) {
- return;
- }
- money.display(player, new_money);
- money.popUp(player, money * -1, false);
- }
- function money.subWithoutPopUp(player_or_id, money) {
- if(money == 0) {
- return;
- }
- config = playerdata.getSurvival(player_or_id);
- new_money = config.getDouble(config, "money", 0) - money;
- config.set(config, "money", new_money);
- config.saveAsync(config);
- player = player.getValid(player_or_id);
- if(player == null) {
- return;
- }
- money.display(player, new_money);
- }
- function money.popUp(player, money, boosted) {
- if($boost_blocker == null) {
- $boost_blocker = false;
- }
- if($boost_blocker) {
- $boost_blocker = false;
- return;
- }
- if(money == 0) {
- return;
- }
- if(money > 0) {
- pre = "+";
- }
- if(money < 0) {
- pre = "-";
- money *= -1;
- }
- if(boosted) {
- $boost_blocker = true;
- post = " §6§k#§rBoosted§6§k#";
- } else {
- post = "";
- }
- //player.action(player, string.concat(pre, "§6", string.number(money), " §rsnuvi", post));
- player.action(player, text.new(string.concat(pre, " ", money.getString(money), " ", post)));
- }
- function money.display(player, money) {
- a = money.split(money);
- gold = string.number(a[0]);
- silver = string.number(a[1]);
- copper = string.number(a[2]);
- sb.add(player, 1, string.concat(icon.getGoldCoin(), gold, " ", icon.getSilverCoin(), silver, " ", icon.getCopperCoin(), copper));
- }
- function money.getString(money) {
- return money.getStringColor(money, "§f");
- }
- function money.getStringColor(money, color) {
- a = money.split(money);
- gold = a[0];
- silver = a[1];
- copper = a[2];
- if(gold == 0) {
- gold_string = "";
- } else {
- gold_string = string.concat(icon.getGoldCoin(), color, string.number(gold));;
- }
- if(silver == 0) {
- silver_string = "";
- } else {
- silver_string = string.concat(icon.getSilverCoin(), color, string.number(silver));;
- }
- if(copper == 0) {
- copper_string = "";
- } else {
- copper_string = string.concat(icon.getCopperCoin(), color, string.number(copper));;
- }
- if(gold == 0 && silver == 0 && copper == 0) {
- copper_string = string.concat(icon.getCopperCoin(), color, string.number(0));;
- }
- return string.concat(gold_string, silver_string, copper_string);
- }
- function money.split(money) {
- array = array.new(3);
- gold = math.roundDown(money / 4096);
- pre_silver = money % 4096;;
- silver = math.roundDown(pre_silver / 64);
- bronze = pre_silver % 64;
- array[0] = gold;
- array[1] = silver;
- array[2] = bronze;
- return array;
- }
- function money.splitCap(money) {
- //cap liegt bei 266304 (64 gold + 64 silver + 64 bronze)
- if(money > 266304) {
- msg.dev("error on money.splitCap");
- return null;
- }
- gold = math.roundDown(money / 4096);
- if(gold > 64) {
- gold = 64;
- }
- money -= gold * 4096;
- silver = math.roundDown(money / 64);
- if(silver > 64) {
- silver = 64;
- }
- money -= silver * 64;
- array = array.new(3);
- array[0] = gold;
- array[1] = silver;
- array[2] = money;
- return array;
- }
- //--------------------------------------------------
- //Plot-Utils
- //--------------------------------------------------
- function plot.getFromId(plot_id, world) {
- iter = plot.iterator(world);
- while(hasNext(iter)) {
- plot = next(iter);
- if(plot.getId(plot) == plot_id) {
- return plot;
- }
- }
- return null;
- }
- function plot.calcCost(world, arg1, arg2) {
- //function plot.calcCost(world, length, width) {
- //function plot.calcCost(world, loc1, loc2) {
- if(isDouble(arg1)) {
- length = arg1;
- width = arg2;
- } else {
- x1 = loc.getX(arg1);
- z1 = loc.getZ(arg1);
- x2 = loc.getX(arg2);
- z2 = loc.getZ(arg2);
- length = math.abs(x1 - x2) + 1;
- width = math.abs(z1 - z2) + 1;
- }
- if(world.getName(world) == "creative") {
- factor = 1;
- } else {
- factor = 3;
- }
- return length * width * factor;
- }
- function plot.getIdFromLocation(location) {
- list = plot.get(location);
- if(list.getSize(list) == 0) {
- plot_id = null;
- } else {
- plot = list.getIndex(list, 0);
- plot_id = plot.getId(plot);
- }
- return plot_id;
- }
- function plot.getIdListFromLocation(location) {
- list = plot.get(location);
- for(i = 0; i < list.getSize(list); i++) {
- plot = list.getIndex(list, i);
- list.setIndex(list, i, plot.getId(plot));
- }
- return list;
- }
- function plot.getHighestId(location) {
- list = plot.get(location);
- iter = iterator(list);
- highest = -1;
- while(hasNext(iter)) {
- plot_id = plot.getId(next(iter));
- if(plot_id > highest) {
- highest = plot_id;
- }
- }
- return highest;
- }
- function plot.addPlayer(plot, player_name) {
- list = plot.getOwners(plot);
- uuid = player.getUuid(player_name);
- if(!list.contains(list, uuid)) {
- list.add(list, uuid);
- }
- }
- function plot.removePlayer(plot, player_name) {
- list = plot.getOwners(plot);
- uuid = player.getUuid(player_name);
- list.remove(list, uuid);
- player_id = player.getId(player.getUuid(player_name));
- plot.removeRank(plot, player_id);
- }
- function plot.getOwnersString(plot) {
- list = plot.getOwners(plot);
- if(list.getSize(list) == 0) {
- return "";
- }
- owners_list = list.new();
- for(i = 0; i < list.getSize(list); i++) {
- list.add(owners_list, player.getName(list.getIndex(list, i)));
- }
- return string.concatList(owners_list, " / ", 0, list.getSize(owners_list) - 1);
- }
- function plot.isLeader(plot, player_or_id) {
- return plot.getRank(plot, player_or_id) == "leader";
- }
- function plot.getLeaderName(plot) {
- plot_leader_id = plot.getLeaderId(plot);
- if(plot_leader_id == null) {
- return "";
- }
- p_name = player.getNameFromId(plot_leader_id);
- if(p_name == null) {
- return "";
- }
- return p_name;
- }
- function plot.getLeaderId(plot) {
- map = plot.getRanksMap(plot);
- iter = map.iterator(map);
- while(hasNext(iter)) {
- element = next(iter);
- rank = map.getValue(element);
- if(rank == "leader") {
- p_id = map.getKey(element);
- }
- }
- return p_id;
- }
- function plot.setLeader(plot, player_or_id) {
- plot.setRank(plot, player_or_id, "leader");
- }
- function plot.isMod(plot, player_or_id) {
- return plot.getRank(plot, player_or_id) == "mod";
- }
- function plot.getMods(plot) {
- list = list.new();
- map = plot.getRanksMap(plot);
- iter = map.iterator(map);
- while(hasNext(iter)) {
- element = next(iter);
- rank = map.getValue(element);
- if(rank == "mod") {
- list.add(list, map.getKey(element));
- }
- }
- return list;
- }
- function plot.setMod(plot, player_or_id) {
- plot.setRank(plot, player_or_id, "mod");
- }
- function plot.canOpenChests(plot, player_or_id) {
- return plot.getRank(plot, player_or_id) == "chest";
- }
- function plot.setChest(plot, player_or_id) {
- plot.setRank(plot, player_or_id, "chest");
- }
- function plot.getAllRanks() {
- return getScriptVar("plot_ranks");
- }
- function plot.getRanksMap(plot) {
- plot_id = plot.getId(plot);
- plot_ranks_map = plot.getAllRanks();
- map = map.get(plot_ranks_map, plot_id);
- if(map == null) {
- map = map.new();
- }
- return map;
- }
- function plot.getChestRanks(plot) {
- list = list.new();
- map = plot.getRanksMap(plot);
- iter = map.iterator(map);
- while(hasNext(iter)) {
- element = next(iter);
- rank = map.getValue(element);
- if(rank == "chest") {
- list.add(list, map.getKey(element));
- }
- }
- return list;
- }
- function plot.getRank(plot, player_or_id) {
- map = plot.getRanksMap(plot);
- player_id = player.getValidId(player_or_id);
- rank = map.get(map, player_id);
- return rank;
- }
- function plot.setRank(plot, player_or_id, rank) {
- player_id = player.getValidId(player_or_id);
- plot_id = plot.getId(plot);
- //Cache
- plot_ranks_map = plot.getAllRanks();
- map = plot.getRanksMap(plot);
- map.add(map, player_id, rank);
- map.add(plot_ranks_map, plot_id, map);
- //DB
- stmt = databank.prepare("INSERT INTO new_plotranks (plot_id, player_id, rank) VALUES (?,?,?) ON DUPLICATE KEY UPDATE rank = ?");
- databank.setInt(stmt, 1, plot_id);
- databank.setInt(stmt, 2, player_id);
- databank.setString(stmt, 3, rank);
- databank.setString(stmt, 4, rank);
- databank.workerExecute(stmt);
- }
- function plot.removeRank(plot, player_or_id) {
- player_id = player.getValidId(player_or_id);
- plot_id = plot.getId(plot);
- //Cache
- plot_ranks_map = plot.getAllRanks();
- map = plot.getRanksMap(plot);
- map.remove(map, player_id);
- map.add(plot_ranks_map, plot_id, map);
- //DB
- stmt = databank.prepare("DELETE FROM new_plotranks WHERE player_id = ? AND plot_id = ?;");
- databank.setInt(stmt, 1, player_id);
- databank.setInt(stmt, 2, plot_id);
- databank.workerExecute(stmt);
- }
- function plot.removeAllPlayers(plot) {
- list = plot.getOwners(plot);
- iter = iterator(list);
- while(hasNext(iter)) {
- plot.removeRank(plot, player.getId(next(iter)));
- }
- }
- function plot.setEdges(plot, location1, location2) {
- //Alte Daten abrufen
- plot_name = plot.getName(plot);
- plot_id = plot.getId(plot);
- list = plot.getOwners(plot);
- flags = plot.getFlags(plot);
- //Neues Plot erstellen und altes Plot löschen
- plot.remove(plot, loc.getWorld(location1));
- new_plot = plot.add(location1, location2, plot_id);
- //Alte Daten auf neuem Plot setzen
- plot.setName(new_plot, plot_name);
- new_list = plot.getOwners(new_plot);
- for(i = 0; i < list.getSize(list); i++) {
- list.add(new_list, list.getIndex(list, i));
- }
- plot.setFlags(new_plot, flags, true);
- return new_plot;
- }
- function plot.getType(plot) {
- if(plot.isCity(plot)) {
- type = "§4[§cCity§4]";
- } elseif(plot.isFree(plot)) {
- type = "§3[§bFree§3]";
- } elseif(plot.isSub(plot)) {
- type = "§6[§eSubPlot§6]";
- } else {
- type = "§6[§ePlot§6]";
- }
- return type;
- }
- function plot.isPlot(plot) {
- return !plot.isCity(plot) && !plot.isFree(plot) && !plot.isSub(plot);
- }
- function plot.hasDisabledSigns(plot) {
- return plot.hasFlags(plot, calcLeftShift(26));
- }
- function plot.isExplosive(plot) {
- return plot.hasFlags(plot, calcLeftShift(27));
- }
- function plot.isCity(plot) {
- return plot.hasFlags(plot, calcLeftShift(28));
- }
- function plot.isFree(plot) {
- return plot.hasFlags(plot, calcLeftShift(29));
- }
- function plot.isSub(plot) {
- return plot.hasFlags(plot, calcLeftShift(30));
- }
- function plot.setDisabledSigns(plot, boolean) {
- plot.setFlags(plot, calcLeftShift(26), boolean);
- }
- function plot.setCity(plot, boolean) {
- plot.setFlags(plot, calcLeftShift(28), boolean);
- }
- function plot.setFree(plot, boolean) {
- plot.setFlags(plot, calcLeftShift(29), boolean);
- plot.setFlags(plot, calcLeftShift(30), !boolean); //Sub-Plot entfernen
- }
- function plot.setSub(plot, boolean) {
- plot.setFlags(plot, calcLeftShift(30), boolean);
- plot.setFlags(plot, calcLeftShift(29), !boolean); //Free-Plot entfernen
- }
- //--------------------------------------------------
- //Loc-Utils
- //--------------------------------------------------
- function loc.getHighestPoint(loc) {
- y = 319;
- loc.setY(loc, y);
- while(y > 0 && block.isAir(block.get(loc))) {
- loc.setY(loc, y);
- y = y - 10;
- }
- while(!block.isAir(block.get(loc))) {
- loc.setY(loc, y);
- y++;
- }
- return loc;
- }
- function loc.getStringColon(loc) {
- world_name = world.getName(loc.getWorld(loc));
- x = string.number(loc.getX(loc));
- y = string.number(loc.getY(loc));
- z = string.number(loc.getZ(loc));
- return string.concat(world_name, ":", x, ":", y, ":", z);
- }
- function loc.getStringSpace(loc) {
- world_name = world.getName(loc.getWorld(loc));
- x = string.number(loc.getX(loc));
- y = string.number(loc.getY(loc));
- z = string.number(loc.getZ(loc));
- return string.concat(world_name, " ", x, " ", y, " ", z);
- }
- function loc.getStringRounded(loc, separator) {
- x = string.number(math.round(loc.getX(loc)));
- y = string.number(math.round(loc.getY(loc)));
- z = string.number(math.round(loc.getZ(loc)));
- return string.concat(separator, x, separator, y, separator, z);
- }
- function loc.isSameWorld(loc1, loc2) {
- return world.getName(loc.getWorld(loc1)) == world.getName(loc.getWorld(loc2));
- }
- function loc.getSubPlot(location) {
- list = plot.get(location);
- iter = iterator(list);
- while(hasNext(iter)) {
- plot = next(iter);
- if(plot.isSub(plot)) {
- return plot;
- }
- }
- return null;
- }
- function loc.isCity(location) {
- list = plot.get(location);
- iter = iterator(list);
- while(hasNext(iter)) {
- plot = next(iter);
- if(plot.isCity(plot)) {
- return true;
- }
- }
- return false;
- }
- function loc.hasPlotId(location, plot_id) {
- return list.contains(plot.getIdListFromLocation(location), plot_id);
- }
- function loc.hasPlotName(location, plot_name) {
- list = plot.get(location);
- iter = iterator(list);
- while(hasNext(iter)) {
- plot = next(iter);
- if(plot.getName(plot) == plot_name) {
- return true;
- }
- }
- return false;
- }
- function loc.isInSurvWorld(location) {
- world_name = world.getName(loc.getWorld(location));
- if(world_name == "world") {
- return true;
- } elseif(world_name == "world_the_end") {
- return true;
- } elseif(world_name == "world_nether") {
- return true;
- }
- return false;
- }
- function loc.isInGamesWorld(location) {
- return loc.getWorld(location) == world.getGames();
- }
- function loc.isInCreativeWorld(location) {
- return loc.getWorld(location) == world.getCreative();
- }
- function loc.round(location) {
- world = loc.getWorld(location);
- x = math.round(loc.getX(location));
- y = math.round(loc.getY(location));
- z = math.round(loc.getZ(location));
- return loc.new(world, x, y, z);
- }
- //--------------------------------------------------
- //Survival-Utils
- //--------------------------------------------------
- function living.setAi(bool) {
- config = getServerConfig();
- config.set(config, "spawnWithAi", bool);
- config.saveAsync(config);
- }
- function living.getAi() {
- config = getServerConfig();
- return config.getBool(config, "spawnWithAi", true);
- }
- function living.setHand(living, item) {
- living.setEquip(living, slot.getHand(), item);
- }
- function living.getHand(living) {
- return living.getEquip(living, slot.getHand());
- }
- function living.getOffHand(living) {
- return living.getEquip(living, slot.getOffHand());
- }
- //--------------------------------------------------
- //Afk-Utils
- //--------------------------------------------------
- function player.isAfk(player) {
- player_uuid = player.getUuid(player);
- afk_map = getScriptVar("afk_map");
- return map.contains(afk_map, player_uuid);
- }
- function player.setAfk(player, boolean) {
- player_uuid = player.getUuid(player);
- afk_map = getScriptVar("afk_map");
- if(boolean) {
- map.add(afk_map, player_uuid, loc.getYaw(entity.getLocation(player)));
- } else {
- map.remove(afk_map, player_uuid);
- }
- }
- //--------------------------------------------------
- //PvP-Utils
- //--------------------------------------------------
- function hasPvpOn(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getBool(config, "pvp", false);
- }
- function setPvp(player_or_id, bool) {
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "pvp", bool);
- config.saveAsync(config);
- }
- //--------------------------------------------------
- //Rank-Utils
- //--------------------------------------------------
- function getRank(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- return config.getString(config, "rank", "§3User");
- }
- function setRank(player_or_id, rank) {
- rank = string.replace(rank, "&", "§");
- config = playerdata.getSurvival(player_or_id);
- config.set(config, "rank", rank);
- config.saveAsync(config);
- }
- function offerRank(player, tech_name) {
- rank = rank.getFromTechName(tech_name);
- msg(player, text.merge(text.new(string.getPrefix("§6Commands")), text.new(" "), text.new("New rank available: "), text.getHoverText(string.getClickText(string.concat("[§", rank, "§r]"), string.concat("/setrank ", player.getName(player), " &", rank)), "Click to set")));
- }
- function rank.offerClan(clan_id, tech_name) {
- leader_uuid = clan.getLeader(clan_id);
- leader = player.get(leader_uuid);
- if(leader == null) {
- mail.send("marvinius", player.getName(leader_uuid), string.concat("New rank available: ", tech_name));
- } else {
- offerRank(leader, tech_name);
- }
- }
- function rank.checkCriteria(player, tech_name) {
- //Playtime
- if(tech_name == "rank.newcomer") {
- return player.getTotalPlaytime(player) >= 1200; //20 Stunden
- }
- if(tech_name == "rank.frequenter") {
- return player.getTotalPlaytime(player) >= 6000; //100 Stunden
- }
- if(tech_name == "rank.legend") {
- return player.getTotalPlaytime(player) >= 42000; //700 Stunden
- }
- //Challenges
- if(tech_name == "rank.challenger") {
- return player.getADTChallengeAmounts(player) >= 1;
- }
- if(tech_name == "rank.mobhunter") {
- return player.getAEChallengeAmounts(player) >= 1;
- }
- if(tech_name == "rank.collector") {
- return player.getAIhallengeAmounts(player) >= 1;
- }
- //Adventure
- /*if(tech_name == "rank.adventurer") {
- return player.getAdventureAmounts(player) >= 1;
- }
- if(tech_name == "rank.explorer") {
- return player.getAdventureAmounts(player) >= 5;
- }
- if(tech_name == "rank.pioneer") {
- return player.getAdventureAmounts(player) >= 10;
- }*/
- //Clans
- /*if(tech_name == "rank.commander") {
- if(player.isClanLeader(player)) {
- clan_id = player.getClanId(player);
- return clan.getMembersAmount(clan_id) >= 5;
- }
- return false;
- }
- if(tech_name == "rank.chief") {
- if(player.isClanLeader(player)) {
- clan_id = player.getClanId(player);
- return clan.getMembersAmount(clan_id) >= 10;
- }
- return false;
- }
- if(tech_name == "rank.lord") {
- if(player.isClanLeader(player)) {
- clan_id = player.getClanId(player);
- return clan.getMembersAmount(clan_id) >= 15;
- }
- return false;
- }*/
- //Quests
- if(tech_name == "rank.volunteer") {
- return quest.getCounter(player) >= 15;
- }
- if(tech_name == "rank.friend") {
- return quest.getCounter(player) >= 50;
- }
- if(tech_name == "rank.altruist") {
- return quest.getCounter(player) >= 500;
- }
- //Plots
- if(tech_name == "rank.settler") {
- return player.usedHisFreePlot(player);
- }
- if(tech_name == "rank.colonizer") {
- return player.hasBigPlotCreated(player);
- }
- if(tech_name == "rank.major") {
- return player.hasPlotRaised(player);
- }
- //Team
- if(tech_name == "rank.admin") {
- return perm.has("isAdmin", player);
- }
- if(tech_name == "rank.builder") {
- return perm.has("isBuilder", player);
- }
- if(tech_name == "rank.dev") {
- return perm.has("isDev", player);
- }
- if(tech_name == "rank.moderator") {
- return perm.has("isMod", player);
- }
- if(tech_name == "rank.supporter") {
- return perm.has("isSupporter", player);
- }
- //Other
- if(tech_name == "rank.vip") {
- return perm.has("isVIP", player);
- }
- if(tech_name == "rank.influencer") {
- return perm.has("isYT", player) || perm.has("isStreamer", player);
- }
- if(tech_name == "rank.sponsor") {
- return perm.has("isSponsor", player);
- }
- if(tech_name == "rank.user") {
- return true;
- }
- return perm.has("setrank.other", player);
- }
- function rank.getRankArray() {
- return getScriptVar("ranks");
- }
- function rank.getFromTechName(tech_name) {
- a = rank.getRankArray();
- a_size = array.getSize(a);
- for(i = 0; i < a_size; i++) {
- if(a[i, 0] == tech_name) {
- return a[i, 1];
- }
- }
- return null;
- }
- function rank.getTechName(rank) {
- a = rank.getRankArray();
- a_size = array.getSize(a);
- for(i = 0; i < a_size; i++) {
- if(a[i, 1] == rank) {
- return a[i, 0];
- }
- }
- return null;
- }
- function rank.choose(player, tech_name) {
- rank = rank.getFromTechName(tech_name);
- msg(player, string.getClickText(string.concat(" [§", rank, "§r]"), string.concat("/setrank ", player.getName(player), " &", rank)));
- }
- function rank.showAll(player) {
- a = rank.getRankArray();
- a_size = array.getSize(a);
- for(i = 0; i < a_size; i++) {
- tech_name = a[i, 0];
- if(rank.checkCriteria(player, tech_name)) {
- rank.choose(player, tech_name);
- }
- }
- }
- //--------------------------------------------------
- //Perm-Utils
- //--------------------------------------------------
- function perm.addGroupToPlayer(player_id, perm_id) {
- stmt = databank.prepare("INSERT INTO new_playerperms (player_id, perm_id) VALUES (?,?);");
- databank.setInt(stmt, 1, player_id);
- databank.setInt(stmt, 2, perm_id);
- databank.workerExecute(stmt);
-
- list = player.getPerms(player_id);
- list.add(list, perm_id);
- perm.initPlayer(player_id);
- }
- function perm.removeGroupFromPlayer(player_id, perm_id) {
- stmt = databank.prepare("DELETE FROM new_playerperms WHERE player_id = ? AND perm_id = ?;");
- databank.setInt(stmt, 1, player_id);
- databank.setInt(stmt, 2, perm_id);
- databank.workerExecute(stmt);
-
- list = player.getPerms(player_id);
- list.remove(list, perm_id);
-
- player_uuid = player.getUuidFromId(player_id);
- player = player.get(player_uuid);
- if(player != null) {
- perm.unloadGroupFromPlayer(perm_id, player);
- }
- }
- function perm.simUser(player) {
- perm.clear(player);
- perm.loadGroupToPlayer(0, player);
- perm.loadGroupToPlayer(14, player);
- perm.update(player);
- }
- function player.removeAllPerms(player_id) {
- stmt = databank.prepare("DELETE FROM new_playerperms WHERE player_id = ?;");
- databank.setInt(stmt, 1, player_id);
- databank.workerExecute(stmt);
- perm.initPlayer(player_id);
- }
- function perm.getAll() {
- return getScriptVar("player_perms");
- }
- function player.getPerms(player_or_id) {
- player_id = player.getValidId(player_or_id);
- map = perm.getAll();
- list = map.get(map, player_id);
- if(list == null) {
- list = list.new();
- map.add(map, player_id, list);
- }
- return map.getOrDefault(perm.getAll(), player_id, list.new());
- }
- function player.getPermsFromDatabank(player_or_id) {
- player_id = player.getValidId(player_or_id);
- permslist = list.new();
- stmt = databank.prepare("SELECT perm_id FROM new_playerperms WHERE player_id = ?;");
- databank.setInt(stmt, 1, player_id);
- result = databank.execute(stmt);
- while(databank.next(result)) {
- list.add(permslist, databank.getInt(result, 1));
- }
- databank.close(result);
- databank.close(stmt);
- return permslist;
- }
- function perm.setGroups(permgroups) {
- setScriptVar("permgroups", permgroups);
- }
- function perm.getGroups() {
- return getScriptVar("permgroups");
- }
- function perm.getNameFromId(permgroup_id) {
- a = perm.getGroups();
- for(i = 0; i < array.getSize(a); i++) {
- if(i == permgroup_id) {
- return a[i, 0];
- }
- }
- return null;
- }
- function perm.getRankFromId(permgroup_id) {
- a = perm.getGroups();
- for(i = 0; i < array.getSize(a); i++) {
- if(i == permgroup_id) {
- return a[i, 1];
- }
- }
- return null;
- }
- function perm.getIdFromGroupname(permgroup_name) {
- a = perm.getGroups();
- for(i = 0; i < array.getSize(a); i++) {
- if(a[i, 0] == permgroup_name) {
- return i;
- }
- }
- return null;
- }
- function perm.getRankFromGroupname(permgroup_name) {
- a = perm.getGroups();
- for(i = 0; i < array.getSize(a); i++) {
- if(a[i, 0] == permgroup_name) {
- return a[i, 1];
- }
- }
- return null;
- }
- function perm.isGroupName(permgroup_name) {
- a = perm.getGroups();
- for(i = 0; i < array.getSize(a); i++) {
- if(a[i, 0] == permgroup_name) {
- return true;
- }
- }
- return false;
- }
- function player.hasPermGroup(player_id, perm_id) {
- permslist = player.getPerms(player_id);
- return list.contains(permslist, perm_id);
- }
- function perm.loadGroupToPlayer(group_id, player) {
- list = perm.getGroupList(group_id);
- iter = iterator(list);
- while(hasNext(iter)) {
- perm = next(iter);
- perm.add(perm, player);
- }
- }
- function perm.unloadGroupFromPlayer(group_id, player) {
- list = perm.getGroupList(group_id);
- iter = iterator(list);
- while(hasNext(iter)) {
- perm = next(iter);
- perm.remove(perm, player);
- }
- }
- function perm.getGroupList(group_id) {
- a = perm.getGroups();
- for(i = 0; i < array.getSize(a); i++) {
- if(i == group_id) {
- return a[i, 2];
- }
- }
- return null;
- }
- function perm.isAwardable(group_id) {
- a = perm.getGroups();
- for(i = 0; i < array.getSize(a); i++) {
- if(i == group_id) {
- return a[i, 3];
- }
- }
- return null;
- }
- function perm.initPlayer(player_or_id) {
- player = player.getValid(player_or_id);
- if(player == null) {
- return;
- }
- perm.clear(player);
- perm.loadGroupToPlayer(0, player);
- permslist = player.getPerms(player);
- iter = iterator(permslist);
- while(hasNext(iter)) {
- perm.loadGroupToPlayer(next(iter), player);
- }
- perm.update(player);
- command.sendHelpWorkaround();
- }
- function command.sendHelpWorkaround() {
- command.unregister("cmdsendworkaround");
- }
- //--------------------------------------------------
- //Nickname-Utils
- //--------------------------------------------------
- function player.setNickName(player, nickname) {
- map.add(getScriptVar("nicknames"), player.getUuid(player), nickname);
- }
- function player.getNickName(player) {
- return map.getOrDefault(getScriptVar("nicknames"), player.getUuid(player), player.getName(player));
- }
- function player.removeNickName(player) {
- map.remove(getScriptVar("nicknames"), player.getUuid(player));
- }
- function player.isNicked(player) {
- return map.contains(getScriptVar("nicknames"), player.getUuid(player));
- }
- //--------------------------------------------------
- //Mail-Utils
- //--------------------------------------------------
- function mail.send(from_name, to_name, string_message) {
- server_config = getServerConfig();
- mail_id = config.getDouble(server_config, "mail_id", 0) + 1;
- config.set(server_config, "mail_id", mail_id);
- config.saveAsync(server_config);
-
- from_id = player.getId(player.getUuid(from_name));
- to_id = player.getId(player.getUuid(to_name));
-
- stmt = databank.prepare("INSERT INTO mails (mail_id, from_id, to_id, readed, time, message) VALUES (?, ?, ?, ?, ?, ?);");
- databank.setInt(stmt, 1, mail_id);
- databank.setInt(stmt, 2, from_id);
- databank.setInt(stmt, 3, to_id);
- databank.setBool(stmt, 4, false);
- databank.setLong(stmt, 5, time.getMillis());
- databank.setString(stmt, 6, string_message);
- databank.workerExecute(stmt);
-
- //Wenn Spieler online, dann Pushmeldung veranlassen
- p = read.player(to_name);
- if(p != null) {
- msg(p, text.merge(text.new(string.concat(string.getPrefix("§bMail"), " §rYou´ve got a new mail from §b", from_name, ". ")), string.getClickText("[§cClick§r]", "/mail new")));
- }
- }
- function mail.checkForNew(player) {
- stmt = databank.prepare("SELECT mail_id, from_id, time, message FROM mails WHERE to_id = ? AND readed = false;");
- to_id = player.getId(player);
- databank.setInt(stmt, 1, to_id);
- result = databank.execute(stmt);
- nextrow = databank.next(result);
- if(!nextrow) {
- databank.close(result);
- databank.close(stmt);
- return;
- }
- newmails = 0;
- while(nextrow) {
- newmails++;
- nextrow = databank.next(result);
- }
- databank.close(result);
- databank.close(stmt);
- if(newmails > 0) {
- if(newmails > 1) {
- msg(player, text.merge(text.new(string.concat(string.getPrefix("§bMail"), " §rYou´ve got §b", string.number(newmails), "§r new mails. ")), string.getClickText("[§cClick§r]", "/mail new")));;
- } else {
- msg(player, text.merge(text.new(string.concat(string.getPrefix("§bMail"), " §rYou´ve got §b1 §rnew mail. ")), string.getClickText("[§cClick§r]", "/mail new")));;
- }
- }
- }
- //--------------------------------------------------
- //Friend-Utils
- //--------------------------------------------------
- function friend.check(player_id, friend_id) {
- stmt = databank.prepare("SELECT friend_id FROM friends WHERE (player_id = ? AND friend_id = ?) OR (player_id = ? AND friend_id = ?);");
- databank.setInt(stmt, 1, player_id);
- databank.setInt(stmt, 2, friend_id);
- databank.setInt(stmt, 3, friend_id);
- databank.setInt(stmt, 4, player_id);
- result = databank.execute(stmt);
- if(databank.next(result)) {
- temp = true;
- } else {
- temp = false;
- }
- databank.close(result);
- databank.close(stmt);
- return temp;
- }
- function friend.add(player_id, friend_id) {
- stmt = databank.prepare("INSERT INTO friends (player_id, friend_id, time) VALUES (?, ?, ?);");
- databank.setInt(stmt, 1, player_id);
- databank.setInt(stmt, 2, friend_id);
- databank.setLong(stmt, 3, time.getMillis());
- databank.workerExecute(stmt);
- }
- function friend.delete(player_id, friend_id) {
- stmt = databank.prepare("DELETE FROM friends WHERE (player_id = ? AND friend_id = ?) OR (player_id = ? AND friend_id = ?);");
- databank.setInt(stmt, 1, player_id);
- databank.setInt(stmt, 2, friend_id);
- databank.workerExecute(stmt);
- }
- function friend.getList(player_id) {
- list = list.new();
- stmt = databank.prepare("SELECT friend_id FROM friends WHERE player_id = ?;");
- databank.setInt(stmt, 1, player_id);
- result = databank.execute(stmt);
- while(databank.next(result)) {
- list.add(list, databank.getInt(result, 1));
- }
- databank.close(result);
- databank.close(stmt);
-
- stmt = databank.prepare("SELECT player_id FROM friends WHERE friend_id = ?;");
- databank.setInt(stmt, 1, player_id);
- result = databank.execute(stmt);
- while(databank.next(result)) {
- list.add(list, databank.getInt(result, 1));
- }
- databank.close(result);
- databank.close(stmt);
- return list;
- }
- function friend.getListOnline(player_id) {
- friends = friend.getList(player_id);
- l = list.new();
- iter = iterator(friends);
- while(hasNext(iter)) {
- f_id = next(iter);
- f_name = player.getNameFromId(f_id);
- if(isOnline(f_name)) {
- list.add(l, f_name);
- }
- }
- return l;
- }
- //--------------------------------------------------
- //Clan-Utils
- //--------------------------------------------------
- function clan.getIdList() {
- file = file.new("scripts/configs/clan_data");
- if(file.exists(file) && file.isDirectory(file)) {
- list = file.getList(file);
- } else {
- list = list.new();
- }
- id_list = list.new();
- iter = iterator(list);
- while(hasNext(iter)) {
- element = next(iter);
- file_name = file.getName(element);
- file_name = string.replace(file_name, ".0.snuvic", "");
- list.add(id_list, read.number(file_name));
- }
- return id_list;
- }
- function clan.loadData() {
- list = clan.getIdList();
- iter = iterator(list);
- map = map.new();
- while(hasNext(iter)) {
- clan_id = next(iter);
- config = config.new("scripts/configs/clan_data", clan_id);
- if(config.exists(config)) {
- config.load(config);
- }
- map.add(map, clan_id, config);
- }
- setScriptVar("clan_data", map);
- }
- function clan.getData(clan_id) {
- if(clan_id == null) {
- msg.dev("script termed. clan_id was null");
- term();
- }
- map = getScriptVar("clan_data");
- config = map.get(map, clan_id);
- if(config == null) {
- config = config.new("scripts/configs/clan_data", clan_id);
- if(config.exists(config)) {
- config.load(config);
- }
- map.add(map, clan_id, config);
- }
- return config;
- }
- function clan.setName(clan_id, name) {
- config = clan.getData(clan_id);
- config.set(config, "name", name);
- config.saveAsync(config);
- }
- function clan.getName(clan_id) {
- config = clan.getData(clan_id);
- temp = config.getString(config, "name", "null");
- if(temp == "null") {
- return null;
- }
- return temp;
- }
- function clan.setTag(clan_id, tag) {
- config = clan.getData(clan_id);
- config.set(config, "tag", tag);
- config.saveAsync(config);
- }
- function clan.getTag(clan_id) {
- config = clan.getData(clan_id);
- temp = config.getString(config, "tag", "null");
- if(temp == "null") {
- return null;
- }
- return temp;
- }
- function clan.setMoney(clan_id, money) {
- config = clan.getData(clan_id);
- config.set(config, "money", money);
- config.saveAsync(config);
- }
- function clan.getMoney(clan_id) {
- config = clan.getData(clan_id);
- return config.getDouble(config, "money", 0);
- }
- function clan.addMoney(clan_id, money) {
- config = clan.getData(clan_id);
- new_money = config.getDouble(config, "money", 0) + money;
- config.set(config, "money", new_money);
- config.saveAsync(config);
- }
- function clan.subMoney(clan_id, money) {
- config = clan.getData(clan_id);
- new_money = config.getDouble(config, "money", 0) - money;
- config.set(config, "money", new_money);
- config.saveAsync(config);
- }
- function clan.setSpawn(clan_id, location) {
- config = clan.getData(clan_id);
- config.set(config, "spawn", string.location(location));
- config.saveAsync(config);
- }
- function clan.getSpawn(clan_id) {
- config = clan.getData(clan_id);
- location = config.getString(config, "spawn", "null");
- if(location == "null") {
- return null;
- }
- return read.location(location);
- }
- function clan.getIdFromName(name) {
- list = clan.getIdList();
- iter = iterator(list);
- while(hasNext(iter)) {
- clan_id = next(iter);
- if(clan.getName(clan_id) == name) {
- return clan_id;
- }
- }
- return null;
- }
- function clan.getIdFromTag(clan_tag) {
- list = clan.getIdList();
- iter = iterator(list);
- while(hasNext(iter)) {
- clan_id = next(iter);
- if(clan.getTag(clan_id) == clan_tag) {
- return clan_id;
- }
- }
- return null;
- }
- function clan.isExistingTag(clan_tag) {
- return !(clan.getIdFromTag(clan_tag) == null);
- }
- function clan.isExistingName(name) {
- return !(clan.getIdFromName(name) == null);
- }
- function clan.getNextFreeId() {
- server_config = getServerConfig();
- id = config.getDouble(server_config, "clan.id.next", 0) + 1;
- config.set(server_config, "clan.id.next", id);
- config.saveAsync(server_config);
- return id;
- }
- function clan.create(name, tag) {
- clan_id = clan.getNextFreeId();
- config = clan.getData(clan_id);
- config.set(config, "name", name);
- config.set(config, "tag", tag);
- config.set(config, "members", 0);
- config.save(config);
- return clan_id;
- }
- function clan.getLeader(clan_id) {
- list = clan.getMembersList(clan_id);
- iter = iterator(list);
- while(hasNext(iter)) {
- player_uuid = next(iter);
- player_id = player.getId(player_uuid);
- if(player.isClanLeader(player_id)) {
- return player_uuid;
- }
- }
- return null;
- }
- function clan.getMembersAmount(clan_id) {
- config = clan.getData(clan_id);
- return config.getDouble(config, "members", 0);
- }
- function clan.setMembersAmount(clan_id, amount) {
- config = clan.getData(clan_id);
- config.set(config, "members", amount);
- config.saveAsync(config);
- }
- function clan.addMember(clan_id, player_or_id, role) {
- //Player
- player.setClanId(player_or_id, clan_id);
- player.setClanRole(player_or_id, role);
- //Clan
- new_amount = clan.getMembersAmount(clan_id) + 1;
- if(isPlayer(player_or_id)) {
- player_uuid = player.getUuid(player_or_id);
- } else {
- player_uuid = player.getUuidFromId(player_or_id);
- }
- config = clan.getData(clan_id);
- config.set(config, string.concat("player_", new_amount), text(player_uuid));
- config.set(config, "members", new_amount);
- config.saveAsync(config);
- }
- function clan.removeMember(clan_id, player_or_id) {
- //Player
- player.setClanId(player_or_id, -1);
- player.setClanRole(player_or_id, "null");
- if(isPlayer(player_or_id)) {
- player_uuid = player.getUuid(player_or_id);
- } else {
- player_uuid = player.getUuidFromId(player_or_id);
- }
- //Clan
- config = clan.getData(clan_id);
- amount = config.getDouble(config, "members", 0);
- for(i = 1; i <= amount; i++) {
- if(config.getString(config, string.concat("player_", i), "null") == text(player_uuid)) {
- break;
- }
- }
- if(i != amount) {
- config.set(config, string.concat("player_", i), config.getString(config, string.concat("player_", amount), "null"));
- }
- config.set(config, string.concat("player_", amount), "null");
- config.set(config, "members", amount - 1);
- config.saveAsync(config);
- }
- function clan.delete(clan_id) {
- //Members
- list = clan.getMembersList(clan_id);
- iter = iterator(list);
- while(hasNext(iter)) {
- player_uuid = next(iter);
- player_id = player.getId(player_uuid);
- player.setClanId(player_id, -1);
- player.setClanRole(player_id, "null");
- }
- //Clan
- config.delete(clan.getData(clan_id));
- map.remove(getScriptVar("clan_data"), clan_id);
- }
- function clan.getMembersList(clan_id) {
- list = list.new();
- config = clan.getData(clan_id);
- amount = config.getDouble(config, "members", 0);
- for(i = 1; i <= amount; i++) {
- player_uuid = read.uuid(config.getString(config, string.concat("player_", i), "null"));
- list.add(list, player_uuid);
- }
- return list;
- }
- function clan.updateHeadNames(clan_id) {
- list = clan.getMembersList(clan_id);
- iter = iterator(list);
- while(hasNext(iter)) {
- p = player.get(next(iter));
- if(p != null) {
- player.setHeadName(p);
- }
- }
- }
- function clan.msg(clan_id, text_or_string) {
- list = clan.getMembersList(clan_id);
- iter = iterator(list);
- while(hasNext(iter)) {
- p = player.get(next(iter));
- if(p != null) {
- msg.prefix(p, "§2Clan", text_or_string);
- }
- }
- }
- function clan.mail(clan_id, from_name, string_message) {
- list = clan.getMembersList(clan_id);
- iter = iterator(list);
- while(hasNext(iter)) {
- to_name = player.getName(next(iter));
- mail.send(from_name, to_name, string_message);
- }
- }
- //--------------------------------------------------
- //Party-Utils
- //--------------------------------------------------
- function player.isInParty(player) {
- return player.getPartyId(player) != null;
- }
- function party.same(player1, player2) {
- return player.getPartyId(player1) == player.getPartyId(player2);
- }
- function player.isPartyLeader(player) {
- return player.getPartyRank(player) == "Leader";
- }
- function player.isPartyLeaderOrMod(player) {
- return player.getPartyRank(player) != "Player";
- }
- function player.getPartyId(player) {
- return map.get(getScriptVar("party_ids"), player.getUuid(player));
- }
- function player.setPartyId(player, party_id) {
- map.add(getScriptVar("party_ids"), player.getUuid(player), party_id);
- }
- function player.delPartyId(player) {
- map.remove(getScriptVar("party_ids"), player.getUuid(player));
- }
- function player.getPartyRank(player) {
- return map.get(getScriptVar("party_ranks"), player.getUuid(player));
- }
- function player.setPartyRank(player, rank) {
- map.add(getScriptVar("party_ranks"), player.getUuid(player), rank);
- }
- function player.delPartyRank(player) {
- map.remove(getScriptVar("party_ranks"), player.getUuid(player));
- }
- function party.getList(party_id) {
- return map.get(getScriptVar("party_lists"), party_id);
- }
- function party.setList(party_id, list) {
- map = getScriptVar("party_lists");
- map.add(map, party_id, list);
- setScriptVar("party_lists", map);
- }
- function party.addPlayer(party_id, player) {
- list.add(party.getList(party_id), player.getUuid(player));
- player.setPartyId(player, party_id);
- }
- //--------------------------------------------------
- //Scheduler-Utils
- //--------------------------------------------------
- function scheduler.add(data_array) {
- list.add(scheduler.getList(), data_array);
- }
- function scheduler.getList() {
- return getScriptVar("scheduler_list");
- }
- function scheduler.addFly(ticks, player, bool) {
- a = array.new(4);
- a[0] = 0;
- a[1] = ticks;
- a[2] = player;
- a[3] = bool;
- scheduler.add(a);
- }
- function scheduler.msgPrefix(ticks, player, prefix, text_or_string) {
- a = array.new(5);
- a[0] = 1;
- a[1] = ticks;
- a[2] = player;
- a[3] = prefix;
- a[4] = text_or_string;
- scheduler.add(a);
- }
- function scheduler.msg(ticks, player, text_or_string) {
- a = array.new(4);
- a[0] = 2;
- a[1] = ticks;
- a[2] = player;
- a[3] = text_or_string;
- scheduler.add(a);
- }
- function scheduler.setBlockMaterial(ticks, block, material, block_update) {
- a = array.new(5);
- a[0] = 3;
- a[1] = ticks;
- a[2] = block;
- a[3] = material;
- a[4] = block_update;
- scheduler.add(a);
- }
- function scheduler.questFinish(ticks, script, player) {
- a = array.new(4);
- a[0] = 4;
- a[1] = ticks;
- a[2] = script;
- a[3] = player;
- scheduler.add(a);
- }
- function scheduler.setBurning(ticks, entity, seconds) {
- a = array.new(4);
- a[0] = 5;
- a[1] = ticks;
- a[2] = entity;
- a[3] = seconds;
- scheduler.add(a);
- }
- function scheduler.spawnEntity(ticks, type, location) {
- a = array.new(4);
- a[0] = 6;
- a[1] = ticks;
- a[2] = type;
- a[3] = location;
- scheduler.add(a);
- }
- function scheduler.removeEntity(ticks, entity) {
- a = array.new(3);
- a[0] = 7;
- a[1] = ticks;
- a[2] = entity;
- scheduler.add(a);
- }
- function scheduler.giveItem(ticks, player, item) {
- a = array.new(4);
- a[0] = 8;
- a[1] = ticks;
- a[2] = player;
- a[3] = item;
- scheduler.add(a);
- }
- function scheduler.giveSingleItem(ticks, player, item) {
- a = array.new(4);
- a[0] = 9;
- a[1] = ticks;
- a[2] = player;
- a[3] = item;
- scheduler.add(a);
- }
- function scheduler.setBlockData(ticks, block, blockdata, block_update) {
- a = array.new(5);
- a[0] = 10;
- a[1] = ticks;
- a[2] = block;
- a[3] = blockdata;
- a[4] = block_update;
- scheduler.add(a);
- }
- //--------------------------------------------------
- //Icon-Utils
- //--------------------------------------------------
- function icon.getGoldCoin() {
- return string.fromCode(63489);
- }
- function icon.getSilverCoin() {
- return string.fromCode(63490);
- }
- function icon.getCopperCoin() {
- return string.fromCode(63491);
- }
- function icon.getExp() {
- return string.fromCode(63492);
- }
- function icon.getBookshelf() {
- return string.fromCode(63493);
- }
- function icon.getCraftingTable() {
- return string.fromCode(63494);
- }
- function icon.getCompass() {
- return string.fromCode(63495);
- }
- function icon.getCake() {
- return string.fromCode(63496);
- }
- function icon.getEnderpearl() {
- return string.fromCode(63497);
- }
- function icon.getHeart() {
- return string.fromCode(63498);
- }
- function icon.getHalfHeart() {
- return string.fromCode(63499);
- }
- function icon.getEmptyHeart() {
- return string.fromCode(63500);
- }
- //--------------------------------------------------
- //Challenge-Utils
- //--------------------------------------------------
- function challenge.display(player, id, challenge, string_message, stage, all_stages) {
- sb.add(player, id, string.concat("§a", challenge, ": ", string_message, " [", string.number(stage), "/", string.number(all_stages), "]"));
- }
- function challenge.removeDisplay(player, id) {
- sb.remove(player, id);
- }
- function player.addChallenge(player_or_id, challenge) {
- config = playerdata.getSurvival(player_or_id);
- string = config.getString(config, "challenge", "");
- if(string == "") {
- config.set(config, "challenge", challenge);
- } else {
- config.set(config, "challenge", string.concat(string, "%", challenge));
- }
- config.saveAsync(config);
- }
- function player.removeChallenge(player_or_id, challenge) {
- config = playerdata.getSurvival(player_or_id);
- string = config.getString(config, "challenge", "");
- string = string.replace(string, string.concat(challenge, "%"), "");
- string = string.replace(string, string.concat("%", challenge), "");
- string = string.replace(string, challenge, "");
- config.set(config, "challenge", string);
- config.saveAsync(config);
- }
- function player.getChallenges(player_or_id) {
- config = playerdata.getSurvival(player_or_id);
- string = config.getString(config, "challenge", "");
- a = string.split("%", string);
- s = set.new();
- for(i = 0; i < array.getSize(a); i++) {
- set.add(s, a[i]);
- }
- return s;
- }
- function challenge.playerHas(player_or_id, challenge) {
- return set.contains(player.getChallenges(player_or_id), challenge);
- }
|