WorldEdit

WorldEdit

42M Downloads

Unable to use JavaAdapter in CraftScripts

Snownee opened this issue ยท 11 comments

commented

WorldEdit Version

7.2.5

Platform Version

Forge

Confirmations

  • I am using the most recent Minecraft release.
  • I am using a version of WorldEdit compatible with my Minecraft version.
  • I am using the latest or recommended version of my platform software.
  • I am NOT using a hybrid server, e.g. a server that combines Bukkit and Forge. Examples include Arclight, Mohist, and Cardboard.
  • I am NOT using a fork of WorldEdit, such as FastAsyncWorldEdit (FAWE) or AsyncWorldEdit (AWE)

Bug Description

Due to the current implementation of MinecraftHidingClassShutter, run the script below will show Access to Java class "adapter1" is prohibited

https://github.com/EngineHub/WorldEdit/blob/master/worldedit-core/src/main/java/com/sk89q/worldedit/scripting/MinecraftHidingClassShutter.java#L30

Which means you can't extend any class by CraftScripts

Expected Behavior

ability to use JavaAdapter in CraftScripts

Reproduction Steps

Use this script:

// $Id$
/*
 * Test CraftScript for WorldEdit
 * Copyright (C) 2021 Snownee
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

let we = com.sk89q.worldedit.WorldEdit.getInstance()
let factory = we.getBlockFactory()
let parser = new JavaAdapter(com.sk89q.worldedit.extension.factory.parser.DefaultBlockParser, {
	parseFromInput: function(input, context) {
		return null
	}
}, we)

Anything Else?

No response

commented

you should be making a custom SimpleInputParser (or any InputParser), not extending DefaultBlockParser

and i'm like 95% sure you can just do that with java's "anonymous class syntax", e.g.

parser = new SimpleInputParser(we) {
  getMatchedAliases: function() { return ImmutableList.of("#mypattern")}
  parseFromSimpleInput: function(input, context) { return MyPattern(...) };
}
we.getPatternFactory().register(parser)

I thought that was a very simple need. So I don't want to import GPL codes or writing a dedicated mod for it. Also I am having some trouble extending abstract class in Rhino.

commented

What do you mean by "GPL codes"? All of worldedit is GPL, you can't not use it.

commented

Why do you need to extend DefaultBlockParser? That's not really an intended usage of the API, if you need to parse stuff there are helpers to do that already [ref].

commented

I want to register my own parser to the the BlockFactory

commented

you should be making a custom SimpleInputParser (or any InputParser), not extending DefaultBlockParser

and i'm like 95% sure you can just do that with java's "anonymous class syntax", e.g.

parser = new SimpleInputParser(we) {
  getMatchedAliases: function() { return ImmutableList.of("#mypattern")}
  parseFromSimpleInput: function(input, context) { return MyPattern(...) };
}
we.getPatternFactory().register(parser)
commented

Why a different block parser? Are you sure you're not looking to add a pattern parser and add it to the existing pattern factory?

commented

What do you mean by "GPL codes"? All of worldedit is GPL, you can't not use it.

I don't want my entire project to become under GPL.

commented

Unfortunately using CraftScripts won't let you avoid that. You must still use a GPL-compatible license even if you write a CraftScript, as that is still linking against WorldEdit.

commented

So is it a bug?

commented

Not being able to use JavaAdapter may be a bug, I'm looking in to it. However, you do not need it to implement a single interface as you need here, so this isn't a blocker.

commented

Fixes by 6008fe7.