mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 12:48:32 +00:00
Plugin API: Allow Plugins without Main class
This commit is contained in:
parent
7297f8d2c0
commit
e3bf38e0b2
@ -85,12 +85,15 @@ class LevelAPI{
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateLevel($name, $seed = false){
|
public function generateLevel($name, $seed = false, $generator = false){
|
||||||
$options = array();
|
$options = array();
|
||||||
if($this->server->api->getProperty("generator-settings") !== false and trim($this->server->api->getProperty("generator-settings")) != ""){
|
if($this->server->api->getProperty("generator-settings") !== false and trim($this->server->api->getProperty("generator-settings")) != ""){
|
||||||
$options["preset"] = $this->server->api->getProperty("generator-settings");
|
$options["preset"] = $this->server->api->getProperty("generator-settings");
|
||||||
}
|
}
|
||||||
if($this->server->api->getProperty("generator") !== false and class_exists($this->server->api->getProperty("generator"))){
|
|
||||||
|
if($generator !== false and class_exists($generator)){
|
||||||
|
$generator = new $generator($options);
|
||||||
|
}elseif($this->server->api->getProperty("generator") !== false and class_exists($this->server->api->getProperty("generator"))){
|
||||||
$generator = $this->server->api->getProperty("generator");
|
$generator = $this->server->api->getProperty("generator");
|
||||||
$generator = new $generator($options);
|
$generator = new $generator($options);
|
||||||
}else{
|
}else{
|
||||||
|
@ -86,11 +86,11 @@ class PluginAPI extends stdClass{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
console("[INFO] Loading plugin \"\x1b[32m".$info["name"]."\x1b[0m\" \x1b[35m".$info["version"]." \x1b[0mby \x1b[36m".$info["author"]."\x1b[0m");
|
console("[INFO] Loading plugin \"\x1b[32m".$info["name"]."\x1b[0m\" \x1b[35m".$info["version"]." \x1b[0mby \x1b[36m".$info["author"]."\x1b[0m");
|
||||||
if(class_exists($info["class"])){
|
if($info["class"] !== "none" and class_exists($info["class"])){
|
||||||
console("[ERROR] Failed loading plugin: class already exists");
|
console("[ERROR] Failed loading plugin: class already exists");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(eval($info["code"]) === false or !class_exists($info["class"])){
|
if(eval($info["code"]) === false or ($info["class"] !== "none" and !class_exists($info["class"]))){
|
||||||
console("[ERROR] Failed loading plugin: evaluation error");
|
console("[ERROR] Failed loading plugin: evaluation error");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -101,6 +101,7 @@ class PluginAPI extends stdClass{
|
|||||||
console("[WARNING] Plugin \"".$info["name"]."\" may not be compatible with the API (".$info["apiversion"]." != ".CURRENT_API_VERSION.")! It can crash or corrupt the server!");
|
console("[WARNING] Plugin \"".$info["name"]."\" may not be compatible with the API (".$info["apiversion"]." != ".CURRENT_API_VERSION.")! It can crash or corrupt the server!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($info["class"] !== "none"){
|
||||||
$object = new $className($this->server->api, false);
|
$object = new $className($this->server->api, false);
|
||||||
if(!($object instanceof Plugin)){
|
if(!($object instanceof Plugin)){
|
||||||
console("[ERROR] Plugin \"\x1b[36m".$info["name"]."\x1b[0m\" doesn't use the Plugin Interface");
|
console("[ERROR] Plugin \"\x1b[36m".$info["name"]."\x1b[0m\" doesn't use the Plugin Interface");
|
||||||
@ -112,6 +113,9 @@ class PluginAPI extends stdClass{
|
|||||||
}else{
|
}else{
|
||||||
$this->plugins[$className] = array($object, $info);
|
$this->plugins[$className] = array($object, $info);
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
$this->plugins[md5($info["name"])] = array(new DummyPlugin($this->server->api, false), $info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(Plugin $plugin){
|
public function get(Plugin $plugin){
|
||||||
@ -197,3 +201,14 @@ interface Plugin{
|
|||||||
public function init();
|
public function init();
|
||||||
public function __destruct();
|
public function __destruct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DummyPlugin implements Plugin{
|
||||||
|
public function __construct(ServerAPI $api, $server = false){
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init(){
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __destruct(){
|
||||||
|
}
|
||||||
|
}
|
@ -122,6 +122,7 @@ define("ICE", 79);
|
|||||||
define("SNOW_BLOCK", 80);
|
define("SNOW_BLOCK", 80);
|
||||||
define("CACTUS", 81);
|
define("CACTUS", 81);
|
||||||
define("CLAY_BLOCK", 82);
|
define("CLAY_BLOCK", 82);
|
||||||
|
define("REEDS", 83);
|
||||||
define("SUGARCANE_BLOCK", 83);
|
define("SUGARCANE_BLOCK", 83);
|
||||||
|
|
||||||
define("FENCE", 85);
|
define("FENCE", 85);
|
||||||
|
@ -40,13 +40,12 @@ class NoiseGeneratorOctaves extends NoiseGenerator{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateNoiseOctaves($floats, $int1, $int2, $int3, $int4, $int5, $int6, $par1 = false, $par2 = false, $par3 = false){
|
public function generateNoiseOctaves($int1, $int2, $int3, $int4, $int5, $int6, $par1 = false, $par2 = false, $par3 = false){
|
||||||
if($par1 === false or $par2 === false or $par3 === false){
|
if($par1 === false or $par2 === false or $par3 === false){
|
||||||
return $this->generateNoiseOctaves($floats, $int1, 10, $int2, $int3, 1, $int4, $int5, 1, $int6);
|
return $this->generateNoiseOctaves($int1, 10, $int2, $int3, 1, $int4, $int5, 1, $int6);
|
||||||
}
|
}
|
||||||
if(!is_array($floats)){
|
|
||||||
$floats = array();
|
$floats = array();
|
||||||
}
|
|
||||||
$cnt = $int4 * $int5 * $int6;
|
$cnt = $int4 * $int5 * $int6;
|
||||||
for($i = 0; $i < $cnt; ++$i){
|
for($i = 0; $i < $cnt; ++$i){
|
||||||
$floats[$i] = 0;
|
$floats[$i] = 0;
|
||||||
@ -61,14 +60,13 @@ class NoiseGeneratorOctaves extends NoiseGenerator{
|
|||||||
$l1 = floor($d2);
|
$l1 = floor($d2);
|
||||||
$l2 = floor($d4);
|
$l2 = floor($d4);
|
||||||
$d2 -= $l1;
|
$d2 -= $l1;
|
||||||
$d4 - $l2;
|
$d4 -= $l2;
|
||||||
$l1 %= 16777216;
|
$l1 %= 16777216;
|
||||||
$l2 %= 16777216;
|
$l2 %= 16777216;
|
||||||
|
|
||||||
$d2 += $l1;
|
$d2 += $l1;
|
||||||
$d4 += $l2;
|
$d4 += $l2;
|
||||||
|
$this->generatorCollection[$j]->populateNoiseArray($floats, $d2, $d3, $d4, $int4, $int5, $int6, $par1 * $d1, $par2 * $d1, $par3 * $d1, $d1);
|
||||||
$this->generatorCollection[$j]->populateNouseArray($floats, $d2, $d3, $d4, $int4, $int5, $int6, $par1 * $d1, $par2 * $d1, $par3 * $d1, $d1);
|
|
||||||
$d1 /= 2;
|
$d1 /= 2;
|
||||||
}
|
}
|
||||||
return $floats;
|
return $floats;
|
||||||
|
@ -40,8 +40,12 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||||||
$this->xCoord = $random->nextFloat() * 256;
|
$this->xCoord = $random->nextFloat() * 256;
|
||||||
$this->yCoord = $random->nextFloat() * 256;
|
$this->yCoord = $random->nextFloat() * 256;
|
||||||
$this->zCoord = $random->nextFloat() * 256;
|
$this->zCoord = $random->nextFloat() * 256;
|
||||||
|
|
||||||
|
for($i = 0; $i < 512; ++$i){
|
||||||
|
$this->permutations[$i] = 0;
|
||||||
|
}
|
||||||
for($i = 0; $i < 256; ++$i){
|
for($i = 0; $i < 256; ++$i){
|
||||||
$this->permutations[] = $i;
|
$this->permutations[$i] = $i;
|
||||||
}
|
}
|
||||||
|
|
||||||
for($i = 0; $i < 256; ++$i){
|
for($i = 0; $i < 256; ++$i){
|
||||||
@ -54,14 +58,15 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final function lerp($par1, $par2, $par3){
|
public final function curve($par1, $par2, $par3){
|
||||||
return $par2 + $par1 * ($par2 - $par2);
|
return $par2 + $par1 * ($par3 - $par2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function grad2D($int, $par1, $par2){
|
public function grad2D($int, $par1, $par2){
|
||||||
$i = $int & 0x0F;
|
$i = $int & 0x0F;
|
||||||
$d1 = (1 - (($i & 0x08) >> 3)) * $par1;
|
$d1 = (1 - (($i & 0x08) >> 3)) * $par1;
|
||||||
$d2 = ($i === 12 or $i === 14) ? $par1:($i < 4 ? 0:$par2);
|
$d2 = ($i === 12 or $i === 14) ? $par1:($i < 4 ? 0:$par2);
|
||||||
|
|
||||||
return (($i & 0x01) === 0 ? $d1:-$d1) + (($i & 0x02) === 0 ? $d2:-$d2);
|
return (($i & 0x01) === 0 ? $d1:-$d1) + (($i & 0x02) === 0 ? $d2:-$d2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +74,7 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||||||
$i = $int & 0x0F;
|
$i = $int & 0x0F;
|
||||||
$d1 = $i < 8 ? $par1 : $par2;
|
$d1 = $i < 8 ? $par1 : $par2;
|
||||||
$d2 = ($i === 12 or $i === 14) ? $par1:($i < 4 ? $par2:$par3);
|
$d2 = ($i === 12 or $i === 14) ? $par1:($i < 4 ? $par2:$par3);
|
||||||
|
|
||||||
return (($i & 0x01) === 0 ? $d1:-$d1) + (($i & 0x02) === 0 ? $d2:-$d2);
|
return (($i & 0x01) === 0 ? $d1:-$d1) + (($i & 0x02) === 0 ? $d2:-$d2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,11 +106,10 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||||||
$j = $this->permutations[$i] + $i6;
|
$j = $this->permutations[$i] + $i6;
|
||||||
$k = $this->permutations[$i3 + 1];
|
$k = $this->permutations[$i3 + 1];
|
||||||
$m = $this->permutations[$k] + $i6;
|
$m = $this->permutations[$k] + $i6;
|
||||||
$d1 = $this->lerp($d5, $this->grad2D($this->permutations[$j], $d4, $d6), $this->grad3D($this->permutations[$m], $d4 - 1, 0, $d6));
|
$d1 = $this->curve($d5, $this->grad2D($this->permutations[$j], $d4, $d6), $this->grad3D($this->permutations[$m], $d4 - 1, 0, $d6));
|
||||||
$d2 = $this->lerp($d5, $this->grad3D($this->permutations[$j + 1], $d4, 0, $d6 - 1), $this->grad3D($this->permutations[$m + 1], $d4 - 1, 0, $d6 - 1));
|
$d2 = $this->curve($d5, $this->grad3D($this->permutations[$j + 1], $d4, 0, $d6 - 1), $this->grad3D($this->permutations[$m + 1], $d4 - 1, 0, $d6 - 1));
|
||||||
|
|
||||||
$d8 = $this->lerp($d7, $d1, $d2);
|
|
||||||
|
|
||||||
|
$d8 = $this->curve($d7, $d1, $d2);
|
||||||
$floats[$n++] += $d8 * $d3;
|
$floats[$n++] += $d8 * $d3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,15 +158,15 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
|
|||||||
$i10 = $this->permutations[$i6 + 1] + $i17;
|
$i10 = $this->permutations[$i6 + 1] + $i17;
|
||||||
$n = $this->permutations[$i10] + $i14;
|
$n = $this->permutations[$i10] + $i14;
|
||||||
$i11 = $this->permutations[$i10 + 1] + $i14;
|
$i11 = $this->permutations[$i10 + 1] + $i14;
|
||||||
$d10 = $this->lerp($d7, $this->grad3D($this->permutations[$i8], $d6, $d14, $d12), $this->grad3D($this->permutations[$n], $d6 - 1, $d14, $d12));
|
$d10 = $this->curve($d7, $this->grad3D($this->permutations[$i8], $d6, $d14, $d12), $this->grad3D($this->permutations[$n], $d6 - 1, $d14, $d12));
|
||||||
$d4 = $this->lerp($d7, $this->grad3D($this->permutations[$i9], $d6, $d14 - 1, $d12), $this->grad3D($this->permutations[$i11], $d6 - 1, $d14 - 1, $d12));
|
$d4 = $this->curve($d7, $this->grad3D($this->permutations[$i9], $d6, $d14 - 1, $d12), $this->grad3D($this->permutations[$i11], $d6 - 1, $d14 - 1, $d12));
|
||||||
$d11 = $this->lerp($d7, $this->grad3D($this->permutations[$i8 + 1], $d6, $d14, $d12 - 1), $this->grad3D($this->permutations[$n + 1], $d6 - 1, $d14, $d12 - 1));
|
$d11 = $this->curve($d7, $this->grad3D($this->permutations[$i8 + 1], $d6, $d14, $d12 - 1), $this->grad3D($this->permutations[$n + 1], $d6 - 1, $d14, $d12 - 1));
|
||||||
$d5 = $this->lerp($d7, $this->grad3D($this->permutations[$i9 + 1], $d6, $d14 - 1, $d12 - 1), $this->grad3D($this->permutations[$i11 + 1], $d6 - 1, $d14 - 1, $d12 - 1));
|
$d5 = $this->curve($d7, $this->grad3D($this->permutations[$i9 + 1], $d6, $d14 - 1, $d12 - 1), $this->grad3D($this->permutations[$i11 + 1], $d6 - 1, $d14 - 1, $d12 - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
$d16 = $this->lerp($d15, $d10, $d4);
|
$d16 = $this->curve($d15, $d10, $d4);
|
||||||
$d17 = $this->lerp($d15, $d11, $d5);
|
$d17 = $this->curve($d15, $d11, $d5);
|
||||||
$d18 = $this->lerp($d13, $d16, $d17);
|
$d18 = $this->curve($d13, $d16, $d17);
|
||||||
$floats[$i++] += $d18 * $d9;
|
$floats[$i++] += $d18 * $d9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user