Fixes issue #167

This commit is contained in:
walterhiggins 2014-12-25 14:04:45 +00:00
parent 4fd37054d9
commit 39ce9061f7
4 changed files with 18 additions and 12 deletions

View file

@ -1,3 +1,4 @@
/*global nashorn, exports, require, Packages, __plugin*/
var cmPriority = Packages.net.canarymod.plugin.Priority,
cmCanary = Packages.net.canarymod.Canary,
cmDispatcher = Packages.net.canarymod.hook.Dispatcher,
@ -40,12 +41,9 @@ exports.on = function(
The workaround is to make the ScriptCraftPlugin java class a Listener.
Should only unregister() registered plugins in ScriptCraft js code.
*/
try {
if (nashorn){
// nashorn
eventType = eventType.class;
} catch ( e ){
// non-nashorn
eventType = eventType;
eventType = require('nashorn-type')(eventType);
}
regd = new cmPluginListener({});
cmHookExecutor.registerHook(regd, __plugin, eventType, eventExecutor, priority);

View file

@ -0,0 +1,8 @@
/*
The .class operator causes problems for non-nashorn Java on Mac OS X and some other
environments. So need to have it in a separate module which should only be loaded in
nashorn environment.
*/
module.exports = function(t){
return t.class;
};

View file

@ -383,6 +383,7 @@ This function takes a single parameter and returns true if it's an operator or h
*/
var global = this;
var server;
global.nashorn = typeof Java !== 'undefined';
/*
private implementation
*/
@ -624,7 +625,7 @@ function __onEnable ( __engine, __plugin, __script ) {
/*
wph 20140312 don't delete self on nashorn until https://bugs.openjdk.java.net/browse/JDK-8034055 is fixed
*/
if ( typeof Java === 'undefined' ) { // Java is an object in Nashorn
if ( !nashorn ) {
delete global.self;
delete global.__engine;
}

View file

@ -29,11 +29,11 @@ function getMaterialHandler( material ){
}
};
}
try {
if (nashorn){
/*
nashorn
*/
var itemTypeClass = ItemType.class;
var itemTypeClass = require('nashorn-type')(ItemType);
var materials = itemTypeClass.getDeclaredFields();
for (var i = 0;i < materials.length; i++ ){
@ -48,19 +48,18 @@ try {
items[name] = getMaterialHandler(materialField.get(ItemType));
}
} catch ( e ){
} else {
// non-nashorn
for (var field in ItemType){
if (ItemType[field] === undefined){
continue;
}
if (ItemType[field].class != ItemType){
if (!(ItemType[field] instanceof ItemType)){
continue;
}
var name = (''+field).replace(/^(.)/,function(a){
return a.toLowerCase();
});
console.log(name);
items[name] = getMaterialHandler(ItemType[field]);
}
}