How to extend PluginBase?
dhalucario opened this issue ยท 3 comments
Player.hidePlayer()
expects a Plugin
as it's first argument, the other version without is deprecated.
I would like to follow the best practice of course. How am I supposed to extend PluginBase from Javascript?
I tried doing the following:
const PluginBase = core.type('org.bukkit.plugin.PluginBase');
class TestPlugin extends PluginBase {}
const TEST_PLUGIN = new TestPlugin();
...
// Later in my event handler:
targetPlayer.hidePlayer(TEST_PLUGIN, player);
But this seems to cause the following error:
[19:12:21 WARN]: TypeError: protoParent is neither Object nor Null
The reason why onEnable
doesn't fire is probably because the plugin isn't being loaded by a plugin manager, so it just never runs
Hey, thank you for your help. I have figured out some similar solution. I just noticed two issues:
onEnable
doesn't seem to run at all. (At least console.log doesn't seem to work in that state)- You need to implement
getDescription
This is the code I used:
const PluginBase = core.type('org.bukkit.plugin.PluginBase'),
const PluginDescriptionFile = core.type('org.bukkit.plugin.PluginDescriptionFile');
const pluginDescriptionFile = new PluginDescriptionFile('Test Plugin', '1.0', 'TestPlugin');
const TestPlugin = new PluginBaseAdapter({
getDescription: () => {
return pluginDescriptionFile;
},
onEnable: () => {
console.log("Test");
},
isEnabled: () => {
return true;
}
});
But yeah, core.plugin
is prolly the better and easier solution.
Notes for other people who might stumble across this:
https://www.graalvm.org/latest/reference-manual/js/JavaInteroperability/
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/plugin/PluginBase.html
if you don't need a specific plugin you can just use core.plugin, but if you want to make your own instance of PluginBase you can use Java.extend
Example:
const PluginBase = Java.type("org.bukkit.plugin.PluginBase")
const TestPlugin = Java.extend(PluginBase, {
onEnable: ()=>{
console.log("New Plugin enabled")
},
isEnabled:()=>{
return true
}
})
const plugin = new TestPlugin()
const player = core.type("org.bukkit.Bukkit").getPlayerExact("Losin6450_2nd")
player.hidePlayer(plugin, player)
But i wouldn't recommend using Java.extend to make an instance of PluginBase as you could just use core.plugin