- Compatible API Versions
- 1.0.0 and higher
- Contributors
- Creadores Program
PHPEngineNK
Run PHP on Nukkit!
Requirements:
JSEngineNK Plugin: https://cloudburstmc.org/resources/jsenginenk.939/
JSENK2: https://cloudburstmc.org/resources/jsenk2.1017/
Know Basic JavaScript.
IMPORTANT
Why did I do it in JSEngineNK?
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
Installation:
First create a script in JSEngineNK as said in your example.
Example:
DO NOT DOWNLOAD THE FILE FROM HERE I ONLY PUT IT TO LET ME POST THE PLUGIN (use the if above to import the code)
Then create an instance of the Engine:
and then you can run PHP in Nukkit!
Default objects globals:
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
Examples:
eval:
run PHP with string or reader!
put:
establish a global object that returns a java class or function (not compatible with javascript functions!)
getEngineName:
returns the name of the engine (quercus) and the lib
setNnClassLoader:
set global objects of classes obtained from the Nnclassloader API
getLanguageVersion:
return PHP version
PHP versión default: 5.3.2
getManager:
return manager engine (quercus)
getEngine:
returns the original engine without the extra functions added by the library (quercus)
getClass:
returns the JS library class
getEngineClass:
returns the original engine class (quercus)
ArrayToCode:
returns PHP code in string separated by lines without needing to put ";" nor the php tag
printPHPCode:
returns PHP code in string to print a message in the console
Do not use in ArrayToCode
ConvertPHP:
returns PHP code in string that converts the arguments into PHP code
Do not use in ArrayToCode
evalFile:
run PHP in a PHP file (remember to create the file first)
In plugins/JSEngineNK/TestPHP/Main.php:
Call Java classes from PHP:
Call Java classes from PHP similar to JSEngineNK's Java.type
Same as Java.type!
If you want to make plugins for your server, do not hesitate to Contact Us!
Discord: https://discord.gg/mrmHcwxXff
WhatsApp channel: https://whatsapp.com/channel/0029Va5bITcGZNCqyYkDYZ0F
2024©
Run PHP on Nukkit!
Requirements:
JSEngineNK Plugin: https://cloudburstmc.org/resources/jsenginenk.939/
JSENK2: https://cloudburstmc.org/resources/jsenk2.1017/
Know Basic JavaScript.
IMPORTANT
Why did I do it in JSEngineNK?
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
JavaScript:
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.
Example:
JavaScript:
const PhpEng = require("PHPEngineNK/org/CreadoresProgram/PHPEngineNK.js");
Then create an instance of the Engine:
JavaScript:
var TestPHP = new PhpEng.PHPEngineNK().build();
Default objects globals:
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
Examples:
eval:
run PHP with string or reader!
JavaScript:
TestPHP.eval("<?php $getLogger->info('hello world!'); ?>");
establish a global object that returns a java class or function (not compatible with javascript functions!)
JavaScript:
TestPHP.put("exampleName", ExampleJavaClass); //call in php: $exampleName->exampleFunction("hello world!");
returns the name of the engine (quercus) and the lib
JavaScript:
console.info("engine: " + TestPHP.getEngineName());
set global objects of classes obtained from the Nnclassloader API
JavaScript:
//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
getManager:
return manager engine (quercus)
getEngine:
returns the original engine without the extra functions added by the library (quercus)
getClass:
returns the JS library class
getEngineClass:
returns the original engine class (quercus)
ArrayToCode:
returns PHP code in string separated by lines without needing to put ";" nor the php tag
JavaScript:
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
JavaScript:
TestPHP.eval("<?php "+TestPHP.printPHPCode("Hello world!")+" ?>");
returns PHP code in string that converts the arguments into PHP code
Do not use in ArrayToCode
JavaScript:
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)
JavaScript:
TestPHP.evalFile(manager.getFile("TestPHP", "Main.php"));
PHP:
<?php
$getLogger->info("hello world!");
?>
Call Java classes from PHP similar to JSEngineNK's Java.type
PHP:
$test = java_class("cn.nukkit.Server");
//Or
import cn.nukkit.Server;
//With import you can extend it with php classes
// Or
$myva = new Java("java.util.Date", $arg1, $arg2);//("class", args...)
//JavaBeans:
$mybean = java_bean("java-bean");
If you want to make plugins for your server, do not hesitate to Contact Us!
Discord: https://discord.gg/mrmHcwxXff
WhatsApp channel: https://whatsapp.com/channel/0029Va5bITcGZNCqyYkDYZ0F
2024©