project uses tabs instead of spaces(as in CONTRIBUTING.md)

This commit is contained in:
GameHerobrine 2022-12-26 07:01:28 +03:00
parent f00318b6ed
commit 62571f26cd
115 changed files with 2291 additions and 2364 deletions

View file

@ -81,13 +81,13 @@ class AchievementAPI{
],
];
private $server;
function __construct(){
$this->server = ServerAPI::request();
$this->server = ServerAPI::request();
}
/**
* Add an achievement
* @param string $achievementId
@ -157,47 +157,47 @@ class AchievementAPI{
}
}
public function viewAchievements($cmd, $params, $issuer, $alias)
{
if(!($issuer instanceof Player) && !isset($params[0])){
return "Please enter a nickname.";
} else{
if(isset($params[0]) && ($this->server->api->ban->isOp($issuer->username) || ! ($issuer instanceof Player))){
$player = $this->server->api->player->get($params[0]);
if($player instanceof Player){
$data = $player->data;
} else{
$data = $this->server->api->player->getOffline(trim($params[0]), false);
}
} else{
$data = $issuer->achievements;
}
}
if($data === false){
return "Player {$params[0]} is not found.";
}
if($data instanceof Config){
$achs = $data->get("achievements");
}else{
$achs = $data;
}
if(count($achs) <= 0){
return "Player {$params[0]} unlocked 0 achievements";
}
$output = "Unlocked Achievements(".count($achs)."/".count(self::$achievements)."): ";
foreach($achs as $achievement => $unlocked){
if($unlocked && isset(self::$achievements[$achievement])){
$info = self::$achievements[$achievement];
$output .= "{$info["name"]}, ";
}
}
return substr($output, 0, - 2);
}
public function viewAchievements($cmd, $params, $issuer, $alias)
{
if(!($issuer instanceof Player) && !isset($params[0])){
return "Please enter a nickname.";
} else{
if(isset($params[0]) && ($this->server->api->ban->isOp($issuer->username) || ! ($issuer instanceof Player))){
$player = $this->server->api->player->get($params[0]);
if($player instanceof Player){
$data = $player->data;
} else{
$data = $this->server->api->player->getOffline(trim($params[0]), false);
}
} else{
$data = $issuer->achievements;
}
}
if($data === false){
return "Player {$params[0]} is not found.";
}
if($data instanceof Config){
$achs = $data->get("achievements");
}else{
$achs = $data;
}
if(count($achs) <= 0){
return "Player {$params[0]} unlocked 0 achievements";
}
$output = "Unlocked Achievements(".count($achs)."/".count(self::$achievements)."): ";
foreach($achs as $achievement => $unlocked){
if($unlocked && isset(self::$achievements[$achievement])){
$info = self::$achievements[$achievement];
$output .= "{$info["name"]}, ";
}
}
return substr($output, 0, - 2);
}
public function init(){
$this->server->api->console->register("ach", "<player>", [$this, "viewAchievements"]);
$this->server->api->console->alias("getplayerachievements", "ach");
$this->server->api->console->cmdWhitelist("ach");
$this->server->api->console->register("ach", "<player>", [$this, "viewAchievements"]);
$this->server->api->console->alias("getplayerachievements", "ach");
$this->server->api->console->cmdWhitelist("ach");
}
}

View file

@ -50,7 +50,7 @@ class BanAPI{
* @param string $cmd Command to Whitelist
*/
public function cmdWhitelist($cmd){
$this->server->api->console->cmdWhitelist($cmd);
$this->server->api->console->cmdWhitelist($cmd);
}
/**
@ -67,21 +67,21 @@ class BanAPI{
}
break;
case "player.block.break":
/**
* @var Player $player
*/
$player = $data["player"];
if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){
$t = new Vector2($data["target"]->x, $data["target"]->z);
$s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){
return false;
}
}
return;
/**
* @var Player $player
*/
$player = $data["player"];
if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){
$t = new Vector2($data["target"]->x, $data["target"]->z);
$s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){
return false;
}
}
return;
case "player.block.place"://Spawn protection detection. Allows OPs to place/break blocks in the spawn area.
$player = $data["player"];
if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){
$player = $data["player"];
if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){
$t = new Vector2($data["block"]->x, $data["block"]->z);
$s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){

View file

@ -435,7 +435,7 @@ class BlockAPI{
$item = $player->getSlot($player->slot);
if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){ //If no block exists or not allowed in CREATIVE
if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){
if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){
$this->cancelAction($target, $player);
return $this->cancelAction($block, $player);
}
@ -443,7 +443,7 @@ class BlockAPI{
if($this->server->api->dhandle("player.block.touch", ["type" => "place", "player" => $player, "block" => $block, "target" => $target, "item" => $item]) === false){
if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){
return $this->cancelAction($block, $player);
return $this->cancelAction($block, $player);
}
}
$this->blockUpdate($target, BLOCK_UPDATE_TOUCH);
@ -532,7 +532,7 @@ class BlockAPI{
$this->server->api->entity->updateRadius($pos, 1);
}elseif($level === BLOCK_UPDATE_RANDOM){
//$this->nextRandomUpdate($pos); old version, change back if any issues will start to happen with this one(please note that old version makes a lot of lag)
$this->scheduleBlockUpdate($pos, (mt_rand(25, 75) + Utils::getRandomUpdateTicks() * 0.05) / 0.05, BLOCK_UPDATE_RANDOM);
$this->scheduleBlockUpdate($pos, (mt_rand(25, 75) + Utils::getRandomUpdateTicks() * 0.05) / 0.05, BLOCK_UPDATE_RANDOM);
}
return $level;
}

View file

@ -12,7 +12,7 @@ class ChatAPI{
$this->server->api->console->register("tell", "<player> <private message ...>", [$this, "commandHandler"]);
$this->server->api->console->register("me", "<action ...>", [$this, "commandHandler"]);
$this->server->api->console->register("say", "<message ...>", [$this, "commandHandler"]);
$this->server->api->console->cmdWhitelist("tell");
$this->server->api->console->cmdWhitelist("tell");
$this->server->api->console->cmdWhitelist("me");
$this->server->api->console->alias("msg", "tell");
}

View file

@ -25,13 +25,13 @@ class ConsoleAPI{
$this->cmdWhitelist("help");
$this->cmdWhitelist("status");
}
/**
* Whitelists a CMD so everyone can issue it - Even non OPs.
* @param string $cmd Command to Whitelist
*/
public function cmdWhitelist($cmd){
$this->server->api->ban->cmdWhitelist[strtolower(trim($cmd))] = true;
$this->server->api->ban->cmdWhitelist[strtolower(trim($cmd))] = true;
}
public function register($cmd, $help, $callback){
@ -304,11 +304,11 @@ class ConsoleLoop extends Thread{
}
while(!$this->stop){
$this->line = $this->readLine();
$this->synchronized(function($t) {
$this->wait();
$this->line = false;
}, $this);
$this->line = $this->readLine();
$this->synchronized(function($t) {
$this->wait();
$this->line = false;
}, $this);
}
if(!extension_loaded("readline")){

View file

@ -1,113 +1,113 @@
<?php
class EntityAPI{
public $entities;
private $server;
private $eCnt = 1;
function __construct(){
$this->entities = [];
$this->server = ServerAPI::request();
$this->serverSpawnAnimals = $this->server->api->getProperty("spawn-animals");
$this->serverSpawnMobs = $this->server->api->getProperty("spawn-mobs");
}
public function init(){
$this->server->api->console->register("summon", "<mob>", [$this, "commandHandler"]);
$this->server->api->console->register("spawnmob", "<mob>", [$this, "commandHandler"]);
$this->server->api->console->register("despawn", "", [$this, "CommandHandler"]);
}
public function commandHandler($cmd, $args, $issuer, $alias){
$mob = [
"chicken" => 10,
"cow" => 11,
"pig" => 12,
"sheep" => 13,
"zombie" => 32,
"creeper" => 33,
"skeleton" => 34,
"spider" => 35,
"pigman" => 36
];
$output = "";
switch($cmd){
case "summon":
case "spawnmob":
if(!($issuer instanceof Player)){
$output .= "Please run this command in-game.";
break;
}
if((count($args) < 1) or (count($args) > 3)){
$output .= "Usage: /$cmd <mob> [amount] [baby]";
break;
}
if(is_int($args[0])) $type = $args[0];
else $type = $mob[strtolower($args[0])];
if($type != (10 or 11 or 12 or 13 or 32 or 33 or 34 or 35 or 36)){
$output .= "Unknown mob.";
break;
}
$mobName = ucfirst(array_flip($mob)[$type]);
if((strtolower($args[1] === "baby") or strtolower($args[2] === "baby")) and !Utils::in_range($type, 10, 13)){
$output .= "$mobName cannot be a baby!";
break;
}
$x = round($issuer->entity->x, 2, PHP_ROUND_HALF_UP);
$y = round($issuer->entity->y, 2, PHP_ROUND_HALF_UP);
$z = round($issuer->entity->z, 2, PHP_ROUND_HALF_UP);
$level = $issuer->entity->level;
$pos = new Position($x, $y, $z, $level);
if(count($args) === 1){//summon <mob>
$this->summon($pos, ENTITY_MOB, $type);
$output .= "$mobName spawned in $x, $y, $z.";
break;
}
elseif(is_numeric($args[1])){//summon <mob> [amount]
$amount = (int) $args[1];
if($amount > 100){
$output .= "Cannot spawn > 100 mobs";
break;
}
$isBaby = false;
if(isset($args[2]) and strtolower($args[2]) === 'baby'){//summon <mob> [amount] [baby]
$isBaby = true;
}
for($cnt = $amount; $cnt > 0; --$cnt){
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => $isBaby]);
}
$output .= "$amount ".($isBaby === 1 ? "Baby" : "")." $mobName".(($type !== 13 || $amount > 1) ? "s" : "")." spawned in $x, $y, $z.";
break;
}
elseif(strtolower($args[1]) == "baby"){//summon <mob> [baby]
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => 1]);
$output .= "Baby $mobName spawned in $x, $y, $z.";
break;
}
break;
case "despawn":
$cnt = 0;
public $entities;
private $server;
private $eCnt = 1;
function __construct(){
$this->entities = [];
$this->server = ServerAPI::request();
$this->serverSpawnAnimals = $this->server->api->getProperty("spawn-animals");
$this->serverSpawnMobs = $this->server->api->getProperty("spawn-mobs");
}
public function init(){
$this->server->api->console->register("summon", "<mob>", [$this, "commandHandler"]);
$this->server->api->console->register("spawnmob", "<mob>", [$this, "commandHandler"]);
$this->server->api->console->register("despawn", "", [$this, "CommandHandler"]);
}
public function commandHandler($cmd, $args, $issuer, $alias){
$mob = [
"chicken" => 10,
"cow" => 11,
"pig" => 12,
"sheep" => 13,
"zombie" => 32,
"creeper" => 33,
"skeleton" => 34,
"spider" => 35,
"pigman" => 36
];
$output = "";
switch($cmd){
case "summon":
case "spawnmob":
if(!($issuer instanceof Player)){
$output .= "Please run this command in-game.";
break;
}
if((count($args) < 1) or (count($args) > 3)){
$output .= "Usage: /$cmd <mob> [amount] [baby]";
break;
}
if(is_int($args[0])) $type = $args[0];
else $type = $mob[strtolower($args[0])];
if($type != (10 or 11 or 12 or 13 or 32 or 33 or 34 or 35 or 36)){
$output .= "Unknown mob.";
break;
}
$mobName = ucfirst(array_flip($mob)[$type]);
if((strtolower($args[1] === "baby") or strtolower($args[2] === "baby")) and !Utils::in_range($type, 10, 13)){
$output .= "$mobName cannot be a baby!";
break;
}
$x = round($issuer->entity->x, 2, PHP_ROUND_HALF_UP);
$y = round($issuer->entity->y, 2, PHP_ROUND_HALF_UP);
$z = round($issuer->entity->z, 2, PHP_ROUND_HALF_UP);
$level = $issuer->entity->level;
$pos = new Position($x, $y, $z, $level);
if(count($args) === 1){//summon <mob>
$this->summon($pos, ENTITY_MOB, $type);
$output .= "$mobName spawned in $x, $y, $z.";
break;
}
elseif(is_numeric($args[1])){//summon <mob> [amount]
$amount = (int) $args[1];
if($amount > 100){
$output .= "Cannot spawn > 100 mobs";
break;
}
$isBaby = false;
if(isset($args[2]) and strtolower($args[2]) === 'baby'){//summon <mob> [amount] [baby]
$isBaby = true;
}
for($cnt = $amount; $cnt > 0; --$cnt){
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => $isBaby]);
}
$output .= "$amount ".($isBaby === 1 ? "Baby" : "")." $mobName".(($type !== 13 || $amount > 1) ? "s" : "")." spawned in $x, $y, $z.";
break;
}
elseif(strtolower($args[1]) == "baby"){//summon <mob> [baby]
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => 1]);
$output .= "Baby $mobName spawned in $x, $y, $z.";
break;
}
break;
case "despawn":
$cnt = 0;
if(!isset($args[0])){
$output .= "/despawn <all or (mobs,objects,items,fallings)>";
break;
}else{
if($args[0] === "all"){
$cnt = 0;
foreach($this->entities as $e){
if(isset($e) && $e != null && !$e->isPlayer()){ //if player, not despawning
$this->remove($e->eid);
$cnt++;
}
}
$cnt = 0;
foreach($this->entities as $e){
if(isset($e) && $e != null && !$e->isPlayer()){ //if player, not despawning
$this->remove($e->eid);
$cnt++;
}
}
}else{
$array = explode(",", strtolower($args[0]));
if(count($array) > 4){
@ -123,173 +123,173 @@ class EntityAPI{
$despawning = substr($list, 0, -4);
$l = $this->server->query("SELECT EID FROM entities WHERE class = ".$despawning.";");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$this->remove($e->eid);
$cnt++;
}
}
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$this->remove($e->eid);
$cnt++;
}
}
}
}
}
$output = "$cnt entities have been despawned!";
break;
}
return $output;
}
public function summon(Position $pos, $class, $type, Array $data = []){
$entity = $this->add($pos->level, $class, $type, [
"x" => $pos->x,
"y" => $pos->y,
"z" => $pos->z
] + $data);
$this->spawnToAll($entity, $pos->level);
}
public function add(Level $level, $class, $type = 0, $data = []){
$eid = $this->eCnt++;
$efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class);
if($efl instanceof PropertyEntity){
$class = $efl->getEntityName();
$this->entities[$eid] = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityType(), $data);
}else{
$this->entities[$eid] = new Entity($level, $eid, $class, $type, $data);
}
$level->entityList[$eid] = &$this->entities[$eid];
$this->server->handle("entity.add", $this->entities[$eid]);
return $this->entities[$eid];
}
public function spawnToAll(Entity $e){
foreach($this->server->api->player->getAll($e->level) as $player){
if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER and $e instanceof Entity){
$e->spawn($player);
}
}
}
public function get($eid){
if(isset($this->entities[$eid])){
return $this->entities[$eid];
}
return false;
}
public function remove($eid){
if(isset($this->entities[$eid])){
$this->entities[$eid]->closed = true;
$output = "$cnt entities have been despawned!";
break;
}
return $output;
}
public function summon(Position $pos, $class, $type, Array $data = []){
$entity = $this->add($pos->level, $class, $type, [
"x" => $pos->x,
"y" => $pos->y,
"z" => $pos->z
] + $data);
$this->spawnToAll($entity, $pos->level);
}
public function add(Level $level, $class, $type = 0, $data = []){
$eid = $this->eCnt++;
$efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class);
if($efl instanceof PropertyEntity){
$class = $efl->getEntityName();
$this->entities[$eid] = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityType(), $data);
}else{
$this->entities[$eid] = new Entity($level, $eid, $class, $type, $data);
}
$level->entityList[$eid] = &$this->entities[$eid];
$this->server->handle("entity.add", $this->entities[$eid]);
return $this->entities[$eid];
}
public function spawnToAll(Entity $e){
foreach($this->server->api->player->getAll($e->level) as $player){
if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER and $e instanceof Entity){
$e->spawn($player);
}
}
}
public function get($eid){
if(isset($this->entities[$eid])){
return $this->entities[$eid];
}
return false;
}
public function remove($eid){
if(isset($this->entities[$eid])){
$this->entities[$eid]->closed = true;
if($this->entities[$eid]->isPlayer()){
$pk = new RemovePlayerPacket;
$pk->eid = $eid;
$pk->clientID = 0;
$this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
}else{
$pk = new RemoveEntityPacket;
$pk->eid = $eid;
$this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
}
$this->server->api->dhandle("entity.remove", $this->entities[$eid]);
$pk = new RemovePlayerPacket;
$pk->eid = $eid;
$pk->clientID = 0;
$this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
}else{
$pk = new RemoveEntityPacket;
$pk->eid = $eid;
$this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
}
$this->server->api->dhandle("entity.remove", $this->entities[$eid]);
unset($this->entities[$eid]->level->entityList[$eid]);
unset($this->entities[$eid]);
$this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";");
}
}
public function updateRadius(Position $center, $radius = 15, $class = false){
$this->server->query("UPDATE entities SET hasUpdate = 1 WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
}
public function getRadius(Position $center, $radius = 15, $class = false){
$entities = [];
$l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$entities[$e->eid] = $e;
}
}
}
return $entities;
}
public function heal($eid, $heal, $cause){
$this->harm($eid, -$heal, $cause);
}
public function harm($eid, $attack, $cause, $force = false){
$e = $this->get($eid);
if($e === false or $e->dead === true){
return false;
}
$e->setHealth($e->getHealth() - $attack, $cause, $force);
}
public function dropRawPos(Position $pos, $item, $speedX, $speedY, $speedZ){
if($item->getID() === AIR or $item->count <= 0){
return;
}
$data = [
"x" => $pos->x,
"y" => $pos->y,
"z" => $pos->z,
"level" => $pos->level,
"speedX" => $speedX,
"speedY" => $speedY,
"speedZ" => $speedZ,
"item" => $item,
];
if($this->server->api->handle("item.drop", $data) !== false){
for($count = $item->count; $count > 0;){
$item->count = min($item->getMaxStackSize(), $count);
$count -= $item->count;
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
$this->spawnToAll($e);
$this->server->api->handle("entity.motion", $e);
}
}
}
public function drop(Position $pos, Item $item){
if($item->getID() === AIR or $item->count <= 0){
return;
}
$data = [
"x" => $pos->x + mt_rand(-10, 10) / 50,
"y" => $pos->y + 0.19,
"z" => $pos->z + mt_rand(-10, 10) / 50,
"level" => $pos->level,
"speedX" => Utils::randomFloat() * 0.2 - 0.1,
"speedY" => 0.2,
"speedZ" => Utils::randomFloat() * 0.2 - 0.1,
"item" => $item,
unset($this->entities[$eid]);
$this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";");
}
}
public function updateRadius(Position $center, $radius = 15, $class = false){
$this->server->query("UPDATE entities SET hasUpdate = 1 WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
}
public function getRadius(Position $center, $radius = 15, $class = false){
$entities = [];
$l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$entities[$e->eid] = $e;
}
}
}
return $entities;
}
public function heal($eid, $heal, $cause){
$this->harm($eid, -$heal, $cause);
}
public function harm($eid, $attack, $cause, $force = false){
$e = $this->get($eid);
if($e === false or $e->dead === true){
return false;
}
$e->setHealth($e->getHealth() - $attack, $cause, $force);
}
public function dropRawPos(Position $pos, $item, $speedX, $speedY, $speedZ){
if($item->getID() === AIR or $item->count <= 0){
return;
}
$data = [
"x" => $pos->x,
"y" => $pos->y,
"z" => $pos->z,
"level" => $pos->level,
"speedX" => $speedX,
"speedY" => $speedY,
"speedZ" => $speedZ,
"item" => $item,
];
if($this->server->api->handle("item.drop", $data) !== false){
for($count = $item->count; $count > 0;){
$item->count = min($item->getMaxStackSize(), $count);
$count -= $item->count;
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
$this->spawnToAll($e);
$this->server->api->handle("entity.motion", $e);
}
}
}
public function spawnAll(Player $player){
foreach($this->getAll($player->level) as $e){
if($e->class !== ENTITY_PLAYER){
$e->spawn($player);
}
}
}
public function getAll($level = null){
if($level instanceof Level){
return $level->entityList;
}
return $this->entities;
}
if($this->server->api->handle("item.drop", $data) !== false){
for($count = $item->count; $count > 0;){
$item->count = min($item->getMaxStackSize(), $count);
$count -= $item->count;
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
$this->spawnToAll($e);
$this->server->api->handle("entity.motion", $e);
}
}
}
public function drop(Position $pos, Item $item){
if($item->getID() === AIR or $item->count <= 0){
return;
}
$data = [
"x" => $pos->x + mt_rand(-10, 10) / 50,
"y" => $pos->y + 0.19,
"z" => $pos->z + mt_rand(-10, 10) / 50,
"level" => $pos->level,
"speedX" => Utils::randomFloat() * 0.2 - 0.1,
"speedY" => 0.2,
"speedZ" => Utils::randomFloat() * 0.2 - 0.1,
"item" => $item,
];
if($this->server->api->handle("item.drop", $data) !== false){
for($count = $item->count; $count > 0;){
$item->count = min($item->getMaxStackSize(), $count);
$count -= $item->count;
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
$this->spawnToAll($e);
$this->server->api->handle("entity.motion", $e);
}
}
}
public function spawnAll(Player $player){
foreach($this->getAll($player->level) as $e){
if($e->class !== ENTITY_PLAYER){
$e->spawn($player);
}
}
}
public function getAll($level = null){
if($level instanceof Level){
return $level->entityList;
}
return $this->entities;
}
}

View file

@ -1,10 +1,10 @@
<?php
class LevelAPI{
/**
* @var Level[]
*/
public $levels;
/**
* @var Level[]
*/
public $levels;
private $server, $default;
public function __construct(){

View file

@ -19,7 +19,7 @@ class PlayerAPI{
$this->registerCmd("spawn");
$this->registerCmd("ping");
$this->server->api->console->alias("lag", "ping");
$this->server->api->console->alias("gm", "gamemode");
$this->server->api->console->alias("gm", "gamemode");
$this->server->api->console->alias("who", "list");
$this->server->api->console->alias("suicide", "kill");
$this->server->api->console->alias("tppos", "tp");
@ -392,7 +392,7 @@ class PlayerAPI{
$data = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default);
$data->save();
}else{
return false;
return false;
}
}

View file

@ -27,7 +27,7 @@ class PluginAPI extends stdClass{
$this->server->api->console->register("version", "", [$this, "commandHandler"]);
$this->server->api->console->cmdWhitelist("version");
if($this->server->extraprops->get("query-plugins")){ //allow players to also view plugins ingame, since query makes names public
$this->server->api->console->cmdWhitelist("plugins");
$this->server->api->console->cmdWhitelist("plugins");
}
$this->server->api->console->alias("pl", "plugins");
$this->server->api->console->alias("ver", "version");
@ -65,7 +65,7 @@ class PluginAPI extends stdClass{
public function __destruct(){
foreach($this->plugins as $p){
if(method_exists($p[0], "__destruct")){$p[0]->__destruct();};
if(method_exists($p[0], "__destruct")){$p[0]->__destruct();};
}
unset($this->plugins);
}
@ -163,7 +163,7 @@ class PluginAPI extends stdClass{
$aver = CURRENT_API_VERSION;
if($pluginInfo["api"] != $aver){
console("[WARNING] API is not the same as Core, might cause bugs({$pluginInfo["api"]} != {$aver})");
console("[WARNING] API is not the same as Core, might cause bugs({$pluginInfo["api"]} != {$aver})");
}
$phr = "phar://$filePath/";