Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
the version of framework that JX got good on, hooo
Browse files Browse the repository at this point in the history
  • Loading branch information
hb432 committed Jul 9, 2020
1 parent e32ac87 commit 16ce202
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 20 deletions.
79 changes: 60 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ const UUID = Java.type('java.util.UUID');
const Location = Java.type('org.bukkit.Location');
const Runnable = Java.extend(Java.type('java.lang.Runnable'));
const ArrayList = Java.type('java.util.ArrayList');
const NBTTagInt = nms.NBTTagInt;
const NBTTagByte = nms.NBTTagByte;
const NBTTagList = nms.NBTTagList;
const NBTTagLong = nms.NBTTagLong;
const NBTTagFloat = nms.NBTTagFloat;
const NBTTagShort = nms.NBTTagShort;
const NBTTagDouble = nms.NBTTagDouble;
const NBTTagString = nms.NBTTagString;
const SecureRandom = Java.type('java.security.SecureRandom');
const NBTTagCompound = nms.NBTTagCompound;
const NBTTagIntArray = nms.NBTTagIntArray;
Expand All @@ -14,7 +21,7 @@ const NBTTagByteArray = nms.NBTTagByteArray;
const tasks = [];
const crypto = new SecureRandom();

export const _ = {
const _ = {
array: (object, provider) => {
if (typeof object === 'number') {
const output = [];
Expand Down Expand Up @@ -129,6 +136,8 @@ export const _ = {
return output;
},
dist: (source, target, flat) => {
typeof source.getLocation === 'function' && (source = source.getLocation());
typeof target.getLocation === 'function' && (target = target.getLocation());
if (source instanceof Location && target instanceof Location && source.getWorld() !== target.getWorld()) {
return Infinity;
}
Expand All @@ -137,18 +146,30 @@ export const _ = {
var deltaZ = source.getZ() - target.getZ();
return Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
},
drop: (source, item, option) => {
typeof source.getLocation === 'function' && (source = source.getLocation());
const method = `dropItem${option ? 'Naturally' : ''}`;
return source.getWorld()[method](source, item);
},
entries: (object) => {
return _.keys(object).map((key) => {
return { key: key, value: object[key] };
});
},
extend: (object, ...objects) => {
return Object.assign(object, ...objects);
},
flat: (array) => {
return array.filter((entry) => {
return entry;
});
return Object.assign(
object,
...objects.map((object) => {
return _.object(Object.getOwnPropertyNames(object), (property) => ({ [property]: object[property] }));
})
);
},
flat: (array, consumer) => {
consumer ||
(consumer = (entry) => {
return _.def(entry);
});
return array.filter(consumer);
},
interval: (script, period) => {
const state = { iteration: null };
Expand Down Expand Up @@ -206,7 +227,7 @@ export const _ = {
},
mirror: (options) => {
options || (options = {});
const mirror = _.extend(options.array || [], {
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()),
Expand All @@ -228,31 +249,37 @@ export const _ = {
(consumer = (entry, index) => {
return { [entry.key || index]: entry.value || entry };
});
return _.extend({}, ..._.flat(array.map(consumer)));
return Object.assign({}, ..._.flat(array.map(consumer)));
},
parse: (data) => {
console.log(core.output(data.value));
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':
const temp = new NBTTagCompound();
temp[`set${data.type}`]('x', data.value);
return temp.get('x');
return NBTTagString.a(data.value);
case 'End':
return null;
case 'List':
const list = new NBTTagList();
data.value.forEach((entry) => list.add(_.parse(entry)));
return list;
case 'ByteArray':
const bytes = new NBTTagByteArray(_.collect());
global.test = bytes;
global.test2 = data.value;
data.value.forEach((entry) => bytes.add(_.parse(entry)));
return bytes;
case 'IntArray':
Expand All @@ -264,9 +291,9 @@ export const _ = {
_.entries(data.value).forEach((entry) => compound.set(entry.key, _.parse(entry.value)));
return compound;
}
} catch (error) {
global.test = data;
console.log(error.stack);
} catch (err0) {
console.error(err0);
throw err0;
}
},
pascal: (string, separator) => {
Expand Down Expand Up @@ -322,7 +349,7 @@ export const _ = {
});
},
polyfill: () => {
_.extend(global, {
Object.assign(global, {
atob: (string) => {
return _.base.decode(string);
},
Expand Down Expand Up @@ -381,13 +408,25 @@ export const _ = {
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[`as${type}`]();
value = data.asString();
break;
case 'End':
value = null;
Expand Down Expand Up @@ -441,7 +480,7 @@ export const _ = {
strain: (object, consumer) => {
consumer ||
(consumer = (entry) => {
return entry.value;
return _.def(entry.value);
});
return _.object(_.entries(object).filter(consumer));
},
Expand Down Expand Up @@ -484,3 +523,5 @@ 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(_);
Loading

0 comments on commit 16ce202

Please sign in to comment.