Run PHP on Nukkit!
JSEngineNK Plugin: https://cloudburstmc.org/resources/jsenginenk.939/
PHPLib Plugin: https://github.com/Trollhunters501/PHPLib
Know Basic JavaScript.
Because in PHP classes and non-object functions are not saved, that means that PHP functions cannot be called and only global objects set by the function (put) or (setNnClassLoader) are maintained. To use PHP you can register a JavaScript function in the manager that then returns PHP code
manager.createCommand("name", "description", "functionUsed", "usage", ["aliase1", "aliase2"], "perm.nk");
//TestPHP return new PHPEngineNK().build();
function functionUsed(sender, args, label, manageCMD){
TestPHP.put("sender", sender);
TestPHP.put("args", args);
TestPHP.put("label", label);
TestPHP.put("manageCMD", manageCMD);
TestPHP.eval("<?php $sender->sendMessage("Hello world!"); ?>");
}
First create a script in JSEngineNK as said in your example.
Check if the Library is installed as follows:
if(!script.getScriptByName("PHPEngineNK")){ //If it is not installed, we install it:
load("https://cdn.jsdelivr.net/gh/Trollhunters501/PHPEngineNK/src/Creadores%20Program/PHPEngineNK.js");
}
Then create an instance of the Engine:
var TestPHP = new PHPEngineNK().build();
and then you can run PHP in Nukkit!
server and getServer = returns the class cn.nukkit.Server
logger and getLogger = returns the JSEngineNK logger
plugin = returns the JSEngineNK main class
manager = returns the manager class JSEngineNK
run PHP with string or reader!
TestPHP.eval("<?php $getLogger->info('hello world!'); ?>");
establish a global object that returns a java class or function (not compatible with javascript functions!)
TestPHP.put("exampleName", ExampleJavaClass); //call in php: $exampleName->exampleFunction("hello world!");
returns the name of the engine (quercus) and the lib
console.info("engine: " + TestPHP.getEngineName());
set global objects of classes obtained from the Nnclassloader API
//first parameter Nnclassloader API code second a json that the variable name is set as global object and the content of the variable is the class obtained from the API
TestPHP.setNnClassLoader({ urls: ["https://testurl.com/test.jar"] }, {
objectName: "class.package.example"
}); //PHP: $objectName->testFunctionInClass("hello world!");
return PHP version
PHP versiΓ³n default: 5.3.2
return manager engine (quercus)
returns the original engine without the extra functions added by the library (quercus)
returns the JS library class
returns the original engine class (quercus)
returns PHP code in string separated by lines without needing to put ";" nor the php tag
TestPHP.eval(TestPHP.ArrayToCode(["$getLogger->info('hello world!')", "$getServer->getLogger()->info('hello world 2!')"]));
returns PHP code in string to print a message in the console
Do not use in ArrayToCode
TestPHP.eval("<?php "+TestPHP.printPHPCode("Hello world!")+" ?>");
returns PHP code in string that converts the arguments into PHP code
Do not use in ArrayToCode
TestPHP.eval("<?php "+TestPHP.ConvertPHP("object", "functionInObject", ["'args (Remember if you want to pass a string use quotes or you will pass it as an object ($))'", "arg2..."])+" ?>");
run PHP in a PHP file (remember to create the file first)
TestPHP.evalFile(manager.getFile("TestPHP", "Main.php"));
<?php
$getLogger->info("hello world!");
?>
Call Java classes from PHP similar to JSEngineNK's Java.type
$test = java_class("cn.nukkit.Server");
//or
import cn.nukkit.Server;
//with import you can extend the Java class with PHP!
Same as Java.type!
Creadores Program Β© 2024