From ceb4d7489b88c0ae60c53c1eb50304b71b02b436 Mon Sep 17 00:00:00 2001 From: hb432 Date: Sat, 25 Jul 2020 10:30:49 -0400 Subject: [PATCH] relative import shift --- README.md | 2 +- index.js | 117 +++++++++++++++++++++++++++++++++++++++++++++++++-- index.min.js | 2 +- 3 files changed, 116 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6d07d87..1393313 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Use `/module add grakkit/framework` to install the module, and `/module update g #### Usage Once installed, this code will import this module to the `framework` variable. ```javascript -const framework = core.import('grakkit/framework'); +const framework = core.import('@grakkit/framework'); ``` # Documentation diff --git a/index.js b/index.js index 2e93a01..8bb13fc 100644 --- a/index.js +++ b/index.js @@ -19,9 +19,11 @@ const NBTTagIntArray = nms.NBTTagIntArray; const NBTTagByteArray = nms.NBTTagByteArray; const tasks = []; +const prompts = {}; +const interfaces = {}; const crypto = new SecureRandom(); -const _ = { +export const _ = { array: (object, provider) => { if (typeof object === 'number') { const output = []; @@ -81,6 +83,32 @@ const _ = { return result; } }, + break: (string, limit, color) => { + const output = [ '' ]; + let index = 0; + let current = 0; + color && (string = _.color(string)); + string.split('\n').forEach((line) => { + line.split(' ').forEach((word) => { + const size = (color ? word.replace(/(§.)/g, '') : word).length; + if (size > limit) { + current > 0 && ++index; + output[index] = word; + current = 0; + ++index; + output[index] = ''; + } else { + current += size; + if (current > limit) { + current = 0; + output[++index] = ''; + } + output[index] += `${output[index] === '' ? '' : ' '}${word}`; + } + }); + }); + return output; + }, camel: (string, separator) => { const pascal = _.pascal(string, separator); return _.lower(pascal[0]) + pascal.slice(1); @@ -385,6 +413,9 @@ const _ = { } }); }, + prompt: (player, callback) => { + prompts[player.getUniqueId().toString()] = callback; + }, rand: { base: () => { return (crypto.nextInt() + 2147483648) / 4294967296; @@ -502,6 +533,21 @@ const _ = { const type = toString.apply(object).split(' ')[1].slice(0, -1); return type === 'Object' ? object.constructor.name : type; }, + ui: (player, rows, title, slots, parent) => { + rows = rows * 9; + const inventory = server.createInventory(player, rows, title); + typeof slots.length === 'number' && (slots = _.object(slots)); + _.entries(slots).forEach((entry) => { + if (_.def(entry.value)) { + const item = entry.value.item; + item && inventory.setItem(Number(entry.key), typeof item === 'function' ? item() : item); + } + }); + const key = inventory.hashCode(); + interfaces[key] = { key: key, slots: slots, parent: parent || null }; + player.openInventory(inventory); + return inventory; + }, upper: (string) => { return string.toUpperCase(); }, @@ -513,6 +559,73 @@ const _ = { } }; +core.event('org.bukkit.event.inventory.InventoryClickEvent', (event) => { + const inventory = event.getClickedInventory() || event.getInventory(); + if (!inventory) return; + const key = inventory.hashCode(); + const data = interfaces[key]; + if (!data) return; + event.setCancelled(true); + const index = event.getSlot(); + const slot = data.slots[index]; + if (!slot || slot.action === null) return; + const player = event.getWhoClicked(); + try { + switch (typeof slot.action) { + case 'object': + _.ui(player, slot.action.rows, slot.action.title, slot.action.slots, inventory); + break; + case 'function': + slot.action(slot.item, index, data); + break; + case 'string': + switch (slot.action) { + case 'exit': + player.closeInventory(); + break; + case 'return': + data.parent ? player.openInventory(data.parent) : player.closeInventory(); + break; + } + break; + } + typeof slot.item === 'function' && inventory.setItem(index, slot.item()); + } catch (error) { + console.error('FrameworkError: An interface element action threw an error while attempting to parse it!'); + console.error(error); + } +}); + +core.event('org.bukkit.event.player.PlayerChatEvent', (event) => { + const uuid = event.getPlayer().getUniqueId().toString(); + const callback = prompts[uuid]; + if (callback) { + event.setCancelled(true); + try { + callback(event.getMessage()); + } catch (error) { + console.error('FrameworkError: A player chat prompt callback threw an error during execution!'); + console.error(error); + } + delete prompts[uuid]; + } +}); + +core.event('org.bukkit.event.player.PlayerToggleSneakEvent', (event) => { + if (event.isSneaking()) return; + const uuid = event.getPlayer().getUniqueId().toString(); + const callback = prompts[uuid]; + if (callback) { + try { + callback(null); + } catch (error) { + console.error('FrameworkError: A player chat prompt callback threw an error during execution!'); + console.error(error); + } + delete prompts[uuid]; + } +}); + core.event('org.bukkit.event.player.PlayerJoinEvent', (event) => { const player = event.getPlayer(); const address = player.getAddress().getAddress().getHostAddress(); @@ -529,5 +642,3 @@ core.event('org.bukkit.event.player.PlayerJoinEvent', (event) => { core.event('org.bukkit.event.server.PluginDisableEvent', (event) => { event.getPlugin() === core.plugin && tasks.forEach((task) => task.cancel()); }); - -core.export(_); diff --git a/index.min.js b/index.min.js index 413ee0e..0fcd3a9 100644 --- a/index.min.js +++ b/index.min.js @@ -1 +1 @@ -const nms=eval(`Packages.net.minecraft.server.${server.getClass().getCanonicalName().split(".")[3]}`),UUID=Java.type("java.util.UUID"),Location=Java.type("org.bukkit.Location"),Runnable=Java.extend(Java.type("java.lang.Runnable")),ArrayList=Java.type("java.util.ArrayList"),NBTTagInt=nms.NBTTagInt,NBTTagByte=nms.NBTTagByte,NBTTagList=nms.NBTTagList,NBTTagLong=nms.NBTTagLong,NBTTagFloat=nms.NBTTagFloat,NBTTagShort=nms.NBTTagShort,NBTTagDouble=nms.NBTTagDouble,NBTTagString=nms.NBTTagString,SecureRandom=Java.type("java.security.SecureRandom"),NBTTagCompound=nms.NBTTagCompound,NBTTagIntArray=nms.NBTTagIntArray,NBTTagByteArray=nms.NBTTagByteArray,tasks=[],crypto=new SecureRandom,_={array:(object,provider)=>{if("number"==typeof object){const output=[];let index=0;for(;indexoutput.push(entry));else if("function"==typeof object.forEachRemaining)object.forEachRemaining(entry=>output.push(entry));else if("number"==typeof object.length){let index=0;for(;index{let index=0,result="";for(;index>6&3,e=63&c;b?c||(e=64):d=e=64,result+=_.base.characters.charAt(a>>2&63),result+=_.base.characters.charAt((3&a)<<4|b>>4&15),result+=_.base.characters.charAt(d),result+=_.base.characters.charAt(e)}return result},decode:string=>{let index=0,result="";for(;index>2&15,f=(3&c)<<6|63&_.base.characters.indexOf(string.charAt(index++));result+=String.fromCharCode((63&a)<<2|b>>4&3),result+=e?String.fromCharCode(e):"",result+=f?String.fromCharCode(f):""}return result}},camel:(string,separator)=>{const pascal=_.pascal(string,separator);return _.lower(pascal[0])+pascal.slice(1)},clamp:(number,min,max)=>numbermax?max:number,collect:(...array)=>{const output=new ArrayList;return array.forEach(entry=>{output.add(entry)}),output},color:string=>string.replace(/(&)/g,"§").replace(/(§§)/g,"&"),def:object=>![void 0,null].includes(object)&&("number"!=typeof object||object==object),define:(object,consumer)=>{consumer||(consumer=entry=>({get:()=>entry.value,set:value=>{entry.value=value}}));const output={};return _.entries(object).forEach(entry=>{const info=consumer(entry);info&&Object.defineProperty(output,entry.key,{get(){if(info.get)return info.get()},set(value){info.set&&info.set(value)}})}),output},dist:(source,target,flat)=>{if("function"==typeof source.getLocation&&(source=source.getLocation()),"function"==typeof target.getLocation&&(target=target.getLocation()),source instanceof Location&&target instanceof Location&&source.getWorld()!==target.getWorld())return 1/0;var deltaX=source.getX()-target.getX(),deltaY=flat?0:source.getY()-target.getY(),deltaZ=source.getZ()-target.getZ();return Math.sqrt(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ)},drop:(source,item,option)=>{"function"==typeof source.getLocation&&(source=source.getLocation());const method=`dropItem${option?"Naturally":""}`;return source.getWorld()[method](source,item)},entries:object=>_.keys(object).map(key=>({key:key,value:object[key]})),extend:(object,...objects)=>Object.assign(object,...objects.map(object=>_.object(Object.getOwnPropertyNames(object),property=>({[property]:object[property]})))),flat:(array,consumer)=>(consumer||(consumer=entry=>_.def(entry)),array.filter(consumer)),interval:(script,period)=>{const state={iteration:null},loop=()=>{try{script()}catch(error){console.error(error)}state.iteration=_.timeout(loop,period)};state.iteration=_.timeout(loop,period);const output={cancel:()=>state.iteration.cancel()};return tasks.push(output),output},iterable:object=>!!object&&("function"==typeof object[Symbol.iterator]&&"string"!=typeof object),key:(object,value)=>_.keys(object)[_.values(object).indexOf(value)],keys:object=>Object.keys(object),lower:string=>string.toLowerCase(),match:(object,filter)=>{switch(typeof filter){case"undefined":return!0;case"function":return filter(object);case"object":switch(_.type(filter)){case"Array":return filter.map(entry=>_.match(object,entry)).includes(!0);case"Object":return!_.keys(filter).map(key=>_.match(object[key],filter[key])).includes(!1);default:return object===filter}default:return object===filter}},mirror:options=>{options||(options={});const mirror=Object.assign(options.array||[],{add:(...args)=>(options.add(...args),_.mirror(options).get()),remove:(...args)=>(options.remove(...args),_.mirror(options).get()),clear:(...args)=>(options.clear(...args),_.mirror(options).get()),get:(...args)=>options.get&&options.get(mirror,...args)});return{get:()=>mirror,set:value=>{mirror.clear(),value.forEach(mirror.add)}}},nms:nms,object:(array,consumer)=>(consumer||(consumer=(entry,index)=>({[entry.key||index]:entry.value||entry})),Object.assign({},..._.flat(array.map(consumer)))),parse:data=>{try{switch(data.type){case"None":return data.value;case"Int":return NBTTagInt.a(data.value);case"Float":return NBTTagFloat.a(data.value);case"Double":return NBTTagDouble.a(data.value);case"Long":return NBTTagLong.a(data.value);case"Short":return NBTTagShort.a(data.value);case"Byte":return NBTTagByte.a(data.value);case"String":return NBTTagString.a(data.value);case"End":return null;case"List":const list=new NBTTagList;return data.value.forEach(entry=>list.add(_.parse(entry))),list;case"ByteArray":const bytes=new NBTTagByteArray(_.collect());return global.test=bytes,global.test2=data.value,data.value.forEach(entry=>bytes.add(_.parse(entry))),bytes;case"IntArray":const ints=new NBTTagIntArray(_.collect());return data.value.forEach(entry=>ints.add(_.parse(entry))),ints;case"Compound":const compound=new NBTTagCompound;return _.entries(data.value).forEach(entry=>compound.set(entry.key,_.parse(entry.value))),compound}}catch(err0){throw console.error(err0),err0}},pascal:(string,separator)=>separator?string.split(separator).map(chunk=>_.pascal(chunk)).join(""):_.upper(string[0])+string.slice(1),player:target=>{let uuid=void 0;const players=Object.assign({},core.data("grakkit/players"));if(target instanceof UUID)uuid=target;else if("string"==typeof target){const online=server.getPlayer(target);if(players[target])uuid=_.uuid(players[target].uuid);else if(online)uuid=online.getUniqueId();else if(_.array(server.getOfflinePlayers()).forEach(offline=>{const stored=offline.getUniqueId();void 0===uuid&&[stored.toString(),offline.getName()].includes(target)&&(uuid=stored)}),void 0===uuid){if(target.includes("."))return{};if(!target.includes("-"))return{};try{uuid=_.uuid(target)}catch(error){uuid=server.getOfflinePlayer(target).getUniqueId()}}}else if("string"==typeof target.uuid)uuid=_.uuid(target.uuid);else if("function"==typeof target.uuid)uuid=_.uuid(target.uuid());else{if("function"!=typeof target.getUniqueId){if(target.constructor===Array)return target.map(_.player);throw`FrameworkError: Cannot convert ${core.output(target)} to standardized player notation!`}uuid=target.getUniqueId()}return Object.assign(players[uuid.toString()]||{uuid:uuid.toString()},{online:server.getPlayer(uuid),offline:server.getOfflinePlayer(uuid)})},polyfill:()=>{Object.assign(global,{atob:string=>_.base.decode(string),btoa:string=>_.base.encode(string),clearImmediate:index=>{tasks[index].cancel()},clearInterval:index=>{tasks[index].cancel()},clearTimeout:index=>{tasks[index].cancel()},setImmediate:script=>(_.timeout(script,0),tasks.length-1),setInterval:(script,period)=>(_.interval(script,period||1),tasks.length-1),setTimeout:(script,period)=>(_.timeout(script,period||1),tasks.length-1)})},rand:{base:()=>(crypto.nextInt()+2147483648)/4294967296,range:(min,max)=>Math.floor(_.rand.base()*(max-min+1))+min,threshold:max=>_.rand.base()_.iterable(object)||"string"==typeof object?object[_.rand.range(0,_.array(object).length-1)]:_.rand.entry(_.keys(object))},raw:string=>string.replace(/(&)/g,"&&").replace(/(§)/g,"&"),serialize:data=>{if([null,void 0].includes(data))return{type:"None",value:data};{let value=void 0;const type=data.getClass().getCanonicalName().split("NBTTag")[1];switch(type){case"Int":value=data.asInt();break;case"Float":value=data.asFloat();break;case"Double":value=data.asDouble();break;case"Long":value=data.asLong();break;case"Short":value=data.asShort();break;case"Byte":value=data.asByte();break;case"String":value=data.asString();break;case"End":value=null;break;case"List":case"ByteArray":case"IntArray":value=_.array(data).map(_.serialize);break;case"Compound":value=_.object(_.array(data.map.entrySet()),entry=>({[entry.getKey()]:_.serialize(entry.getValue())}))}return{type:type,value:value}}},simplify:(...context)=>{let output=null;const object=context[0];switch(_.type(object)){case"Array":output=[];for(let entry of object)context.includes(entry)||output.push(_.simplify(entry,...context));output=_.flat(output),output.length||(output=null);break;case"Object":output={};for(let key of _.keys(object))context.includes(object[key])||(output[key]=_.simplify(object[key],...context));output=_.strain(output),_.keys(output).length||(output=null);break;default:output=object}return output},splice:(string,separator,...index)=>string.split(separator).slice(...index).join(separator),strain:(object,consumer)=>(consumer||(consumer=entry=>_.def(entry.value)),_.object(_.entries(object).filter(consumer))),timeout:(script,period)=>{const state={cancel:!1},runnable=new Runnable({run:()=>state.cancel||script()});server.getScheduler().runTaskLater(core.plugin,runnable,Math.ceil(period/50));const output={cancel:()=>state.cancel=!0};return tasks.push(output),output},type:object=>{const type=toString.apply(object).split(" ")[1].slice(0,-1);return"Object"===type?object.constructor.name:type},upper:string=>string.toUpperCase(),uuid:string=>string instanceof UUID?string:_.def(string)?UUID.fromString(string):UUID.randomUUID(),values:object=>Object.values(object)};core.event("org.bukkit.event.player.PlayerJoinEvent",event=>{const player=event.getPlayer(),address=player.getAddress().getAddress().getHostAddress(),name=player.getName(),uuid=player.getUniqueId().toString(),info={address:address,name:name,uuid:uuid};Object.assign(core.data("grakkit/players"),{[address]:info,[name]:info,[uuid]:info})}),core.event("org.bukkit.event.server.PluginDisableEvent",event=>{event.getPlugin()===core.plugin&&tasks.forEach(task=>task.cancel())}),core.export(_); \ No newline at end of file +const nms=eval(`Packages.net.minecraft.server.${server.getClass().getCanonicalName().split(".")[3]}`),UUID=Java.type("java.util.UUID"),Location=Java.type("org.bukkit.Location"),Runnable=Java.extend(Java.type("java.lang.Runnable")),ArrayList=Java.type("java.util.ArrayList"),NBTTagInt=nms.NBTTagInt,NBTTagByte=nms.NBTTagByte,NBTTagList=nms.NBTTagList,NBTTagLong=nms.NBTTagLong,NBTTagFloat=nms.NBTTagFloat,NBTTagShort=nms.NBTTagShort,NBTTagDouble=nms.NBTTagDouble,NBTTagString=nms.NBTTagString,SecureRandom=Java.type("java.security.SecureRandom"),NBTTagCompound=nms.NBTTagCompound,NBTTagIntArray=nms.NBTTagIntArray,NBTTagByteArray=nms.NBTTagByteArray,tasks=[],prompts={},interfaces={},crypto=new SecureRandom;export const _={array:(object,provider)=>{if("number"==typeof object){const output=[];let index=0;for(;indexoutput.push(entry));else if("function"==typeof object.forEachRemaining)object.forEachRemaining(entry=>output.push(entry));else if("number"==typeof object.length){let index=0;for(;index{let index=0,result="";for(;index>6&3,e=63&c;b?c||(e=64):d=e=64,result+=_.base.characters.charAt(a>>2&63),result+=_.base.characters.charAt((3&a)<<4|b>>4&15),result+=_.base.characters.charAt(d),result+=_.base.characters.charAt(e)}return result},decode:string=>{let index=0,result="";for(;index>2&15,f=(3&c)<<6|63&_.base.characters.indexOf(string.charAt(index++));result+=String.fromCharCode((63&a)<<2|b>>4&3),result+=e?String.fromCharCode(e):"",result+=f?String.fromCharCode(f):""}return result}},break:(string,limit,color)=>{const output=[""];let index=0,current=0;return color&&(string=_.color(string)),string.split("\n").forEach(line=>{line.split(" ").forEach(word=>{const size=(color?word.replace(/(§.)/g,""):word).length;size>limit?(current>0&&++index,output[index]=word,current=0,++index,output[index]=""):(current+=size,current>limit&&(current=0,output[++index]=""),output[index]+=`${""===output[index]?"":" "}${word}`)})}),output},camel:(string,separator)=>{const pascal=_.pascal(string,separator);return _.lower(pascal[0])+pascal.slice(1)},clamp:(number,min,max)=>numbermax?max:number,collect:(...array)=>{const output=new ArrayList;return array.forEach(entry=>{output.add(entry)}),output},color:string=>string.replace(/(&)/g,"§").replace(/(§§)/g,"&"),def:object=>![void 0,null].includes(object)&&("number"!=typeof object||object==object),define:(object,consumer)=>{consumer||(consumer=entry=>({get:()=>entry.value,set:value=>{entry.value=value}}));const output={};return _.entries(object).forEach(entry=>{const info=consumer(entry);info&&Object.defineProperty(output,entry.key,{get(){if(info.get)return info.get()},set(value){info.set&&info.set(value)}})}),output},dist:(source,target,flat)=>{if("function"==typeof source.getLocation&&(source=source.getLocation()),"function"==typeof target.getLocation&&(target=target.getLocation()),source instanceof Location&&target instanceof Location&&source.getWorld()!==target.getWorld())return 1/0;var deltaX=source.getX()-target.getX(),deltaY=flat?0:source.getY()-target.getY(),deltaZ=source.getZ()-target.getZ();return Math.sqrt(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ)},drop:(source,item,option)=>{"function"==typeof source.getLocation&&(source=source.getLocation());const method=`dropItem${option?"Naturally":""}`;return source.getWorld()[method](source,item)},entries:object=>_.keys(object).map(key=>({key:key,value:object[key]})),extend:(object,...objects)=>Object.assign(object,...objects.map(object=>_.object(Object.getOwnPropertyNames(object),property=>({[property]:object[property]})))),flat:(array,consumer)=>(consumer||(consumer=entry=>_.def(entry)),array.filter(consumer)),interval:(script,period)=>{const state={iteration:null},loop=()=>{try{script()}catch(error){console.error(error)}state.iteration=_.timeout(loop,period)};state.iteration=_.timeout(loop,period);const output={cancel:()=>state.iteration.cancel()};return tasks.push(output),output},iterable:object=>!!object&&("function"==typeof object[Symbol.iterator]&&"string"!=typeof object),key:(object,value)=>_.keys(object)[_.values(object).indexOf(value)],keys:object=>Object.keys(object),lower:string=>string.toLowerCase(),match:(object,filter)=>{switch(typeof filter){case"undefined":return!0;case"function":return filter(object);case"object":switch(_.type(filter)){case"Array":return filter.map(entry=>_.match(object,entry)).includes(!0);case"Object":return!_.keys(filter).map(key=>_.match(object[key],filter[key])).includes(!1);default:return object===filter}default:return object===filter}},mirror:options=>{options||(options={});const mirror=Object.assign(options.array||[],{add:(...args)=>(options.add(...args),_.mirror(options).get()),remove:(...args)=>(options.remove(...args),_.mirror(options).get()),clear:(...args)=>(options.clear(...args),_.mirror(options).get()),get:(...args)=>options.get&&options.get(mirror,...args)});return{get:()=>mirror,set:value=>{mirror.clear(),value.forEach(mirror.add)}}},nms:nms,object:(array,consumer)=>(consumer||(consumer=(entry,index)=>({[entry.key||index]:entry.value||entry})),Object.assign({},..._.flat(array.map(consumer)))),parse:data=>{try{switch(data.type){case"None":return data.value;case"Int":return NBTTagInt.a(data.value);case"Float":return NBTTagFloat.a(data.value);case"Double":return NBTTagDouble.a(data.value);case"Long":return NBTTagLong.a(data.value);case"Short":return NBTTagShort.a(data.value);case"Byte":return NBTTagByte.a(data.value);case"String":return NBTTagString.a(data.value);case"End":return null;case"List":const list=new NBTTagList;return data.value.forEach(entry=>list.add(_.parse(entry))),list;case"ByteArray":const bytes=new NBTTagByteArray(_.collect());return global.test=bytes,global.test2=data.value,data.value.forEach(entry=>bytes.add(_.parse(entry))),bytes;case"IntArray":const ints=new NBTTagIntArray(_.collect());return data.value.forEach(entry=>ints.add(_.parse(entry))),ints;case"Compound":const compound=new NBTTagCompound;return _.entries(data.value).forEach(entry=>compound.set(entry.key,_.parse(entry.value))),compound}}catch(err0){throw console.error(err0),err0}},pascal:(string,separator)=>separator?string.split(separator).map(chunk=>_.pascal(chunk)).join(""):_.upper(string[0])+string.slice(1),player:target=>{let uuid=void 0;const players=Object.assign({},core.data("grakkit/players"));if(target instanceof UUID)uuid=target;else if("string"==typeof target){const online=server.getPlayer(target);if(players[target])uuid=_.uuid(players[target].uuid);else if(online)uuid=online.getUniqueId();else if(_.array(server.getOfflinePlayers()).forEach(offline=>{const stored=offline.getUniqueId();void 0===uuid&&[stored.toString(),offline.getName()].includes(target)&&(uuid=stored)}),void 0===uuid){if(target.includes("."))return{};if(!target.includes("-"))return{};try{uuid=_.uuid(target)}catch(error){uuid=server.getOfflinePlayer(target).getUniqueId()}}}else if("string"==typeof target.uuid)uuid=_.uuid(target.uuid);else if("function"==typeof target.uuid)uuid=_.uuid(target.uuid());else{if("function"!=typeof target.getUniqueId){if(target.constructor===Array)return target.map(_.player);throw`FrameworkError: Cannot convert ${core.output(target)} to standardized player notation!`}uuid=target.getUniqueId()}return Object.assign(players[uuid.toString()]||{uuid:uuid.toString()},{online:server.getPlayer(uuid),offline:server.getOfflinePlayer(uuid)})},polyfill:()=>{Object.assign(global,{atob:string=>_.base.decode(string),btoa:string=>_.base.encode(string),clearImmediate:index=>{tasks[index].cancel()},clearInterval:index=>{tasks[index].cancel()},clearTimeout:index=>{tasks[index].cancel()},setImmediate:script=>(_.timeout(script,0),tasks.length-1),setInterval:(script,period)=>(_.interval(script,period||1),tasks.length-1),setTimeout:(script,period)=>(_.timeout(script,period||1),tasks.length-1)})},prompt:(player,callback)=>{prompts[player.getUniqueId().toString()]=callback},rand:{base:()=>(crypto.nextInt()+2147483648)/4294967296,range:(min,max)=>Math.floor(_.rand.base()*(max-min+1))+min,threshold:max=>_.rand.base()_.iterable(object)||"string"==typeof object?object[_.rand.range(0,_.array(object).length-1)]:_.rand.entry(_.keys(object))},raw:string=>string.replace(/(&)/g,"&&").replace(/(§)/g,"&"),serialize:data=>{if([null,void 0].includes(data))return{type:"None",value:data};{let value=void 0;const type=data.getClass().getCanonicalName().split("NBTTag")[1];switch(type){case"Int":value=data.asInt();break;case"Float":value=data.asFloat();break;case"Double":value=data.asDouble();break;case"Long":value=data.asLong();break;case"Short":value=data.asShort();break;case"Byte":value=data.asByte();break;case"String":value=data.asString();break;case"End":value=null;break;case"List":case"ByteArray":case"IntArray":value=_.array(data).map(_.serialize);break;case"Compound":value=_.object(_.array(data.map.entrySet()),entry=>({[entry.getKey()]:_.serialize(entry.getValue())}))}return{type:type,value:value}}},simplify:(...context)=>{let output=null;const object=context[0];switch(_.type(object)){case"Array":output=[];for(let entry of object)context.includes(entry)||output.push(_.simplify(entry,...context));output=_.flat(output),output.length||(output=null);break;case"Object":output={};for(let key of _.keys(object))context.includes(object[key])||(output[key]=_.simplify(object[key],...context));output=_.strain(output),_.keys(output).length||(output=null);break;default:output=object}return output},splice:(string,separator,...index)=>string.split(separator).slice(...index).join(separator),strain:(object,consumer)=>(consumer||(consumer=entry=>_.def(entry.value)),_.object(_.entries(object).filter(consumer))),timeout:(script,period)=>{const state={cancel:!1},runnable=new Runnable({run:()=>state.cancel||script()});server.getScheduler().runTaskLater(core.plugin,runnable,Math.ceil(period/50));const output={cancel:()=>state.cancel=!0};return tasks.push(output),output},type:object=>{const type=toString.apply(object).split(" ")[1].slice(0,-1);return"Object"===type?object.constructor.name:type},ui:(player,rows,title,slots,parent)=>{rows*=9;const inventory=server.createInventory(player,rows,title);"number"==typeof slots.length&&(slots=_.object(slots)),_.entries(slots).forEach(entry=>{if(_.def(entry.value)){const item=entry.value.item;item&&inventory.setItem(Number(entry.key),"function"==typeof item?item():item)}});const key=inventory.hashCode();return interfaces[key]={key:key,slots:slots,parent:parent||null},player.openInventory(inventory),inventory},upper:string=>string.toUpperCase(),uuid:string=>string instanceof UUID?string:_.def(string)?UUID.fromString(string):UUID.randomUUID(),values:object=>Object.values(object)};core.event("org.bukkit.event.inventory.InventoryClickEvent",event=>{const inventory=event.getClickedInventory()||event.getInventory();if(!inventory)return;const key=inventory.hashCode(),data=interfaces[key];if(!data)return;event.setCancelled(!0);const index=event.getSlot(),slot=data.slots[index];if(!slot||null===slot.action)return;const player=event.getWhoClicked();try{switch(typeof slot.action){case"object":_.ui(player,slot.action.rows,slot.action.title,slot.action.slots,inventory);break;case"function":slot.action(slot.item,index,data);break;case"string":switch(slot.action){case"exit":player.closeInventory();break;case"return":data.parent?player.openInventory(data.parent):player.closeInventory()}}"function"==typeof slot.item&&inventory.setItem(index,slot.item())}catch(error){console.error("FrameworkError: An interface element action threw an error while attempting to parse it!"),console.error(error)}}),core.event("org.bukkit.event.player.PlayerChatEvent",event=>{const uuid=event.getPlayer().getUniqueId().toString(),callback=prompts[uuid];if(callback){event.setCancelled(!0);try{callback(event.getMessage())}catch(error){console.error("FrameworkError: A player chat prompt callback threw an error during execution!"),console.error(error)}delete prompts[uuid]}}),core.event("org.bukkit.event.player.PlayerToggleSneakEvent",event=>{if(event.isSneaking())return;const uuid=event.getPlayer().getUniqueId().toString(),callback=prompts[uuid];if(callback){try{callback(null)}catch(error){console.error("FrameworkError: A player chat prompt callback threw an error during execution!"),console.error(error)}delete prompts[uuid]}}),core.event("org.bukkit.event.player.PlayerJoinEvent",event=>{const player=event.getPlayer(),address=player.getAddress().getAddress().getHostAddress(),name=player.getName(),uuid=player.getUniqueId().toString(),info={address:address,name:name,uuid:uuid};Object.assign(core.data("grakkit/players"),{[address]:info,[name]:info,[uuid]:info})}),core.event("org.bukkit.event.server.PluginDisableEvent",event=>{event.getPlugin()===core.plugin&&tasks.forEach(task=>task.cancel())}); \ No newline at end of file