Skip to content

Commit

Permalink
I just want everyone to know that I'm so done with Java and this crap.
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSpyce committed May 30, 2018
1 parent 3ed7511 commit 8588d69
Show file tree
Hide file tree
Showing 41 changed files with 219 additions and 857 deletions.
3 changes: 0 additions & 3 deletions lib/consts.js

This file was deleted.

38 changes: 16 additions & 22 deletions lib/internal/bootstrap/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,25 @@
* reference.
*/

var _process = require('internal/process/core');
var _require = require('internal/require');
var fs = require('internal/fs/index');
var path = require('internal/path/index');
var os = require('internal/os/index');
var assert = require('internal/assert');
var async = require('internal/async');
var lang = require('internal/lang');
var safety = require('internal/safety');
var promise = require('internal/promise');
var events = require('internal/events');
var permissions = require('internal/permissions');
var commands = require('internal/commands');
var tts = require('internal/tts');
var _process = require('process/core');
var _require = global.require = require('require');
var fs = require('fs');
var path = require('path');
var os = require('os');
var assert = require('assert');
var async = require('async');
var lang = require('lang');
var safety = require('safety');
var promise = require('promise');
var events = require('events');
var permissions = require('permissions');
var commands = require('commands');
var tts = require('tts');

function initializeCore() {
var entry = path.normalize('./plugins/Thiq/' + process.config.main);
try {
_require('tpm');
} catch (ex) {
console.error("tpm is not installed. To install, follow the directions at https://github.com/thiq/node_modules/tpm");
console.error("Without tpm, you will not be able to install or validate your packages.");
}
var entry = path.normalize(process.cwd() + process.config.main);
console.debug('Environment setup completed. Running entry file ' + entry);
var entryContents = fs.readFile(entry);
var entryContents = fs.readFileSync(entry);
var wrapped = '(function (require, __filename) {' + entryContents + '\n})';
var compiled = eval(wrapped);
var args = [
Expand Down
94 changes: 67 additions & 27 deletions lib/internal/bootstrap/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* modules.
*/


global = this;

Object.prototype.toString = function () {
Expand Down Expand Up @@ -36,10 +35,11 @@ function evalScript(javascript) {
while (ex && ex.unwrap) {
ex = ex.unwrap().cause;
}
ex = (ex || { message: "Unknown error" }).message;
ex = (ex || {
message: "Unknown error"
}).message;
}

console.log(ex);
if (/syntax error/i.test(ex)) {
throw "\n" + javascript;
} else {
Expand All @@ -49,6 +49,7 @@ function evalScript(javascript) {
}

var Bukkit = org.bukkit.Bukkit;

(function () {

var BufferedReader = Java.type('java.io.BufferedReader');
Expand All @@ -68,22 +69,21 @@ var Bukkit = org.bukkit.Bukkit;
'(function (exports, module, require, process, plugin) {',
'\n})'
];

var process = {
config: configureProcess(),
cwd: function() {
return './plugins/Thiq/';
}
};
global.process = configureProcess();

function NativeModule(id) {
this.filename = 'lib/' + id + '.js';
this.filename = 'lib/internal/' + id + '.js';
this.id = id;
this.exports = {};
this.reflect = undefined;
this.exportsKeys = undefined;
this.loaded = false;
this.loading = true;
this.isNative = true;
}

NativeModule.prototype.toString = function () {
return '[NativeModule ' + this.id + ']';
}

NativeModule._source = {}; // TODO: setup natives
Expand All @@ -92,7 +92,7 @@ var Bukkit = org.bukkit.Bukkit;
var loaderExports = {
NativeModule
};
var loaderId = 'internal/bootstrap/loader';
var loaderId = 'bootstrap/loader';

NativeModule.require = function (id) {
if (id[0] == '@') return eval(id.substr(1));
Expand All @@ -101,6 +101,9 @@ var Bukkit = org.bukkit.Bukkit;
if (cached && (cached.loaded || cached.loading)) return cached.exports;

var nativeModule = new NativeModule(id);
// this is so fucking stupid but for some reason .compile() doesn't do a valid check
// if the fucking file works or not
if (!fs_exists(process.cwd() + nativeModule.filename)) throw new Error();
nativeModule.cache();
nativeModule.compile();

Expand All @@ -115,12 +118,13 @@ var Bukkit = org.bukkit.Bukkit;
NativeModule._cache[this.id] = this;
}

NativeModule.getCached = function(id) {
NativeModule.getCached = function (id) {
return NativeModule._cache[id];
}

NativeModule.prototype.compile = function () {
var self = this;

function build(contents) {
var wrapped = NativeModule.wrap(contents);
var args = [
Expand All @@ -136,20 +140,25 @@ var Bukkit = org.bukkit.Bukkit;
self.loaded = true;
} catch (ex) {
if (ex.derivesFromRequire) throw ex;
console.error('An error occured when reading ' + self.filename + ': ' + ex.message);
console.error(ex.getStackTrace());
console.error('An internal error occured when reading ' + self.filename + ': ' + ex.message);
console.error(ex);
throw ex;
} finally {
self.loading = false;
}
}

try {
script = fs_read('./plugins/Thiq/' + this.filename);

if (fs_exists(process.cwd() + this.filename)) {
script = fs_read(process.cwd() + this.filename);
console.debug('Found local file for ' + this.id);
build(script);
console.debug('Built ' + this.id + ' off of local script');
} catch (ex) {
} else {
var resx = hasResource(this.filename);
try {
console.log(resx.length.toString());
} catch (ex) {
throw new Error('File does not exist in resources');
}
var fIn = new BufferedReader(new InputStreamReader(resx));
var line;
var string = '';
Expand All @@ -158,9 +167,7 @@ var Bukkit = org.bukkit.Bukkit;
}
fIn.close();
build(string);
console.debug('Built ' + this.id + ' off of embedded script');
}

return this.exports;
}

Expand Down Expand Up @@ -214,19 +221,52 @@ var Bukkit = org.bukkit.Bukkit;
}

function configureProcess() {
var config = fs_read('./plugins/Thiq/package.json');
var process = {
config: {},
cwd: function () {
return './plugins/Thiq/';
}
};
var config = fs_read(process.cwd() + 'package.json');
try {
var json = JSON.parse(config);
return json;
process.config = json;
} catch (ex) {
var err = new Error("Error reading package.json: " + ex.message);
throw err;
}

return process;
}

NativeModule.require('internal/logger');
NativeModule.require('internal/util/types');
NativeModule.require('internal/bootstrap/core');
var debugMessages = process.config.verbose_logging;

function log(msg, level, verbose) {
if (verbose && !debugMessages) return;
if (!level) level = "f";
if (msg instanceof Array) {
loader.server.consoleSender.sendMessage("\xA7" + level + "[Thiq] " + msg.join('\n'));
} else {
loader.server.consoleSender.sendMessage("\xA7" + level + "[Thiq] " + msg);
}
}

var console = global.console = {
log: log,
warn: function (msg) {
log(msg, 'd', false)
},
debug: function (msg) {
log(msg, 'a', true)
},
error: function (msg) {
log(msg, 'c', false)
},
trace: log
};

NativeModule.require('process/core');
NativeModule.require('bootstrap/core');

return loaderExports;
})();
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/internal/commands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var _require = require('internal/require');
var consts = require('constants');

/**
* Registers a command for usage. All scripts can use this.
Expand Down
90 changes: 90 additions & 0 deletions lib/internal/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
var isWindows = process.platform === 'win32';

module.exports = {
// Alphabet chars.
CHAR_UPPERCASE_A: 65,
/* A */
CHAR_LOWERCASE_A: 97,
/* a */
CHAR_UPPERCASE_Z: 90,
/* Z */
CHAR_LOWERCASE_Z: 122,
/* z */

// Non-alphabetic chars.
CHAR_DOT: 46,
/* . */
CHAR_FORWARD_SLASH: 47,
/* / */
CHAR_BACKWARD_SLASH: 92,
/* \ */
CHAR_VERTICAL_LINE: 124,
/* | */
CHAR_COLON: 58,
/* : */
CHAR_QUESTION_MARK: 63,
/* ? */
CHAR_UNDERSCORE: 95,
/* _ */
CHAR_LINE_FEED: 10,
/* \n */
CHAR_CARRIAGE_RETURN: 13,
/* \r */
CHAR_TAB: 9,
/* \t */
CHAR_FORM_FEED: 12,
/* \f */
CHAR_EXCLAMATION_MARK: 33,
/* ! */
CHAR_HASH: 35,
/* # */
CHAR_SPACE: 32,
/* */
CHAR_NO_BREAK_SPACE: 160,
/* \u00A0 */
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
/* \uFEFF */
CHAR_LEFT_SQUARE_BRACKET: 91,
/* [ */
CHAR_RIGHT_SQUARE_BRACKET: 93,
/* ] */
CHAR_LEFT_ANGLE_BRACKET: 60,
/* < */
CHAR_RIGHT_ANGLE_BRACKET: 62,
/* > */
CHAR_LEFT_CURLY_BRACKET: 123,
/* { */
CHAR_RIGHT_CURLY_BRACKET: 125,
/* } */
CHAR_HYPHEN_MINUS: 45,
/* - */
CHAR_PLUS: 43,
/* + */
CHAR_DOUBLE_QUOTE: 34,
/* " */
CHAR_SINGLE_QUOTE: 39,
/* ' */
CHAR_PERCENT: 37,
/* % */
CHAR_SEMICOLON: 59,
/* ; */
CHAR_CIRCUMFLEX_ACCENT: 94,
/* ^ */
CHAR_GRAVE_ACCENT: 96,
/* ` */
CHAR_AT: 64,
/* @ */
CHAR_AMPERSAND: 38,
/* & */
CHAR_EQUAL: 61,
/* = */

// Digits
CHAR_0: 48,
/* 0 */
CHAR_9: 57,
/* 9 */

EOL: isWindows ? '\r\n' : '\n'

}
1 change: 0 additions & 1 deletion node_modules/fs/index.js → lib/internal/fs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* jshint ignore:start */

var async = require('async');

var BufferedReader = require('@java.io.BufferedReader');
var InputStreamReader = require('@java.io.InputStreamReader');
var FileInputStream = require('@java.io.FileInputStream');
Expand Down

0 comments on commit 8588d69

Please sign in to comment.