mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Attacking entities fixed
This commit is contained in:
parent
1f8987183b
commit
9a3f887f44
@ -42,7 +42,6 @@ class ConsoleAPI{
|
|||||||
$this->register("status", "", array($this, "defaultCommands"));
|
$this->register("status", "", array($this, "defaultCommands"));
|
||||||
$this->register("difficulty", "<0|1|2>", array($this, "defaultCommands"));
|
$this->register("difficulty", "<0|1|2>", array($this, "defaultCommands"));
|
||||||
$this->register("invisible", "<on|off>", array($this, "defaultCommands"));
|
$this->register("invisible", "<on|off>", array($this, "defaultCommands"));
|
||||||
$this->register("save-all", "", array($this, "defaultCommands"));
|
|
||||||
$this->register("stop", "", array($this, "defaultCommands"));
|
$this->register("stop", "", array($this, "defaultCommands"));
|
||||||
$this->register("defaultgamemode", "<mode>", array($this, "defaultCommands"));
|
$this->register("defaultgamemode", "<mode>", array($this, "defaultCommands"));
|
||||||
$this->server->api->ban->cmdWhitelist("help");
|
$this->server->api->ban->cmdWhitelist("help");
|
||||||
@ -126,10 +125,6 @@ class ConsoleAPI{
|
|||||||
$this->server->api->setProperty("difficulty", (int) $s);
|
$this->server->api->setProperty("difficulty", (int) $s);
|
||||||
$output .= "Difficulty changed to ".$this->server->difficulty."\n";
|
$output .= "Difficulty changed to ".$this->server->difficulty."\n";
|
||||||
break;
|
break;
|
||||||
case "save-all":
|
|
||||||
$this->server->save();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "?":
|
case "?":
|
||||||
if($issuer !== "console" and $issuer !== "rcon"){
|
if($issuer !== "console" and $issuer !== "rcon"){
|
||||||
break;
|
break;
|
||||||
@ -202,8 +197,7 @@ class ConsoleAPI{
|
|||||||
$params = (string) substr($line, $end + 1);
|
$params = (string) substr($line, $end + 1);
|
||||||
|
|
||||||
if(isset($this->alias[$cmd])){
|
if(isset($this->alias[$cmd])){
|
||||||
$this->run($this->alias[$cmd] . " " .$params, $issuer, $cmd);
|
return $this->run($this->alias[$cmd] . " " .$params, $issuer, $cmd);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if($issuer instanceof Player){
|
if($issuer instanceof Player){
|
||||||
console("[DEBUG] \x1b[33m".$issuer->username."\x1b[0m issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2);
|
console("[DEBUG] \x1b[33m".$issuer->username."\x1b[0m issued server command: ".ltrim("$alias ")."/$cmd ".$params, true, true, 2);
|
||||||
@ -227,10 +221,11 @@ class ConsoleAPI{
|
|||||||
$offsetshift += strlen($selector[0]) - strlen($p) + 1;
|
$offsetshift += strlen($selector[0]) - strlen($p) + 1;
|
||||||
break;
|
break;
|
||||||
case "all":
|
case "all":
|
||||||
|
$output = "";
|
||||||
foreach($this->server->api->player->getAll() as $p){
|
foreach($this->server->api->player->getAll() as $p){
|
||||||
$this->run($cmd . " ". substr_replace($params, $p->username, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias);
|
$output .= $this->run($cmd . " ". substr_replace($params, $p->username, $selector[1] + $offsetshift - 1, strlen($selector[0]) + 1), $issuer, $alias);
|
||||||
}
|
}
|
||||||
return;
|
return $output;
|
||||||
case "random":
|
case "random":
|
||||||
$l = array();
|
$l = array();
|
||||||
foreach($this->server->api->player->getAll() as $p){
|
foreach($this->server->api->player->getAll() as $p){
|
||||||
|
@ -45,6 +45,9 @@ class LevelAPI{
|
|||||||
|
|
||||||
public function init(){
|
public function init(){
|
||||||
$this->server->api->console->register("seed", "[world]", array($this, "commandHandler"));
|
$this->server->api->console->register("seed", "[world]", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("save-all", "", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("save-on", "", array($this, "commandHandler"));
|
||||||
|
$this->server->api->console->register("save-off", "", array($this, "commandHandler"));
|
||||||
$this->default = $this->server->api->getProperty("level-name");
|
$this->default = $this->server->api->getProperty("level-name");
|
||||||
if($this->loadLevel($this->default) === false){
|
if($this->loadLevel($this->default) === false){
|
||||||
$this->generateLevel($this->default);
|
$this->generateLevel($this->default);
|
||||||
@ -56,6 +59,18 @@ class LevelAPI{
|
|||||||
public function commandHandler($cmd, $params, $issuer, $alias){
|
public function commandHandler($cmd, $params, $issuer, $alias){
|
||||||
$output = "";
|
$output = "";
|
||||||
switch($cmd){
|
switch($cmd){
|
||||||
|
case "save-all":
|
||||||
|
$save = $this->server->saveEnabled;
|
||||||
|
$this->server->saveEnabled = true;
|
||||||
|
$this->saveAll();
|
||||||
|
$this->server->saveEnabled = $save;
|
||||||
|
break;
|
||||||
|
case "save-on":
|
||||||
|
$this->server->saveEnabled = true;
|
||||||
|
break;
|
||||||
|
case "save-off":
|
||||||
|
$this->server->saveEnabled = false;
|
||||||
|
break;
|
||||||
case "seed":
|
case "seed":
|
||||||
if(!isset($params[0]) and ($issuer instanceof Player)){
|
if(!isset($params[0]) and ($issuer instanceof Player)){
|
||||||
$output .= "Seed: ".$issuer->level->getSeed()."\n";
|
$output .= "Seed: ".$issuer->level->getSeed()."\n";
|
||||||
@ -139,6 +154,12 @@ class LevelAPI{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function saveAll(){
|
||||||
|
foreach($this->levels as $level){
|
||||||
|
$level->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getSpawn(){
|
public function getSpawn(){
|
||||||
return $this->server->spawn;
|
return $this->server->spawn;
|
||||||
}
|
}
|
||||||
@ -157,80 +178,4 @@ class LevelAPI{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save($final = false){
|
|
||||||
if($this->mapName !== false){
|
|
||||||
$this->levelData["Time"] = $this->time;
|
|
||||||
file_put_contents($this->mapDir."level.dat", serialize($this->levelData));
|
|
||||||
$this->map->saveMap($final);
|
|
||||||
$this->trigger("server.save", $final);
|
|
||||||
if(count($this->entities) > 0){
|
|
||||||
$entities = array();
|
|
||||||
foreach($this->entities as $entity){
|
|
||||||
if($entity->class === ENTITY_MOB){
|
|
||||||
$entities[] = array(
|
|
||||||
"id" => $entity->type,
|
|
||||||
"Color" => @$entity->data["Color"],
|
|
||||||
"Sheared" => @$entity->data["Sheared"],
|
|
||||||
"Health" => $entity->health,
|
|
||||||
"Pos" => array(
|
|
||||||
0 => $entity->x,
|
|
||||||
1 => $entity->y,
|
|
||||||
2 => $entity->z,
|
|
||||||
),
|
|
||||||
"Rotation" => array(
|
|
||||||
0 => $entity->yaw,
|
|
||||||
1 => $entity->pitch,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}elseif($entity->class === ENTITY_OBJECT){
|
|
||||||
$entities[] = array(
|
|
||||||
"id" => $entity->type,
|
|
||||||
"TileX" => $entity->x,
|
|
||||||
"TileX" => $entity->y,
|
|
||||||
"TileX" => $entity->z,
|
|
||||||
"Health" => $entity->health,
|
|
||||||
"Motive" => $entity->data["Motive"],
|
|
||||||
"Pos" => array(
|
|
||||||
0 => $entity->x,
|
|
||||||
1 => $entity->y,
|
|
||||||
2 => $entity->z,
|
|
||||||
),
|
|
||||||
"Rotation" => array(
|
|
||||||
0 => $entity->yaw,
|
|
||||||
1 => $entity->pitch,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}elseif($entity->class === ENTITY_ITEM){
|
|
||||||
$entities[] = array(
|
|
||||||
"id" => 64,
|
|
||||||
"Item" => array(
|
|
||||||
"id" => $entity->type,
|
|
||||||
"Damage" => $entity->meta,
|
|
||||||
"Count" => $entity->stack,
|
|
||||||
),
|
|
||||||
"Health" => $entity->health,
|
|
||||||
"Pos" => array(
|
|
||||||
0 => $entity->x,
|
|
||||||
1 => $entity->y,
|
|
||||||
2 => $entity->z,
|
|
||||||
),
|
|
||||||
"Rotation" => array(
|
|
||||||
0 => 0,
|
|
||||||
1 => 0,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file_put_contents($this->mapDir."entities.dat", serialize($entities));
|
|
||||||
}
|
|
||||||
if(count($this->tileEntities) > 0){
|
|
||||||
$tiles = array();
|
|
||||||
foreach($this->tileEntities as $tile){
|
|
||||||
$tiles[] = $tile->data;
|
|
||||||
}
|
|
||||||
file_put_contents($this->mapDir."tileEntities.dat", serialize($tiles));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1039,8 +1039,8 @@ class Player{
|
|||||||
if($this->spawned === false){
|
if($this->spawned === false){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if($this->gamemode !== VIEW and $this->blocked === false and isset($this->server->entities[$data["target"]]) and $this->entity->distance($this->server->entities[$data["target"]]) <= 8){
|
|
||||||
$target = $this->server->api->entity->get($data["target"]);
|
$target = $this->server->api->entity->get($data["target"]);
|
||||||
|
if($this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity) and $this->entity->distance($target) <= 8){
|
||||||
$data["targetentity"] = $target;
|
$data["targetentity"] = $target;
|
||||||
$data["entity"] = $this->entity;
|
$data["entity"] = $this->entity;
|
||||||
if(!($target instanceof Entity)){
|
if(!($target instanceof Entity)){
|
||||||
|
@ -27,7 +27,7 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
|
|
||||||
class PocketMinecraftServer{
|
class PocketMinecraftServer{
|
||||||
public $tCnt;
|
public $tCnt;
|
||||||
public $version, $invisible, $api, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd;
|
public $version, $invisible, $api, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $saveEnabled;
|
||||||
private $port, $serverip, $database, $interface, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick;
|
private $port, $serverip, $database, $interface, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick;
|
||||||
|
|
||||||
private function load(){
|
private function load(){
|
||||||
@ -65,6 +65,7 @@ class PocketMinecraftServer{
|
|||||||
$this->whitelist = false;
|
$this->whitelist = false;
|
||||||
$this->clients = array();
|
$this->clients = array();
|
||||||
$this->spawn = false;
|
$this->spawn = false;
|
||||||
|
$this->saveEnabled = true;
|
||||||
$this->tickMeasure = array_fill(0, 40, 0);
|
$this->tickMeasure = array_fill(0, 40, 0);
|
||||||
$this->setType("normal");
|
$this->setType("normal");
|
||||||
$this->interface = new MinecraftInterface("255.255.255.255", $this->port, true, false, $this->serverip);
|
$this->interface = new MinecraftInterface("255.255.255.255", $this->port, true, false, $this->serverip);
|
||||||
|
@ -179,7 +179,7 @@ class Entity extends Position{
|
|||||||
|
|
||||||
private function spawnDrops(){
|
private function spawnDrops(){
|
||||||
foreach($this->getDrops() as $drop){
|
foreach($this->getDrops() as $drop){
|
||||||
$this->server->api->block->drop($this, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF), true);
|
$this->server->api->entity->drop($this, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ class Level{
|
|||||||
$this->time = $time;
|
$this->time = $time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->nextSave < $now and $this->server->saveEnabled === true){
|
||||||
foreach($this->usedChunks as $i => $c){
|
foreach($this->usedChunks as $i => $c){
|
||||||
if(count($c) === 0){
|
if(count($c) === 0){
|
||||||
unset($this->usedChunks[$i]);
|
unset($this->usedChunks[$i]);
|
||||||
@ -75,10 +76,7 @@ class Level{
|
|||||||
$this->level->unloadChunk((int) array_pop($X), (int) $Z);
|
$this->level->unloadChunk((int) array_pop($X), (int) $Z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->nextSave < $now){
|
|
||||||
$this->save();
|
$this->save();
|
||||||
$this->lastSave = $now + 90;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +86,9 @@ class Level{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function save(){
|
public function save(){
|
||||||
|
if($this->server->saveEnabled === false){
|
||||||
|
return;
|
||||||
|
}
|
||||||
$entities = array();
|
$entities = array();
|
||||||
foreach($this->server->api->entity->getAll($this) as $entity){
|
foreach($this->server->api->entity->getAll($this) as $entity){
|
||||||
if($entity->class === ENTITY_MOB){
|
if($entity->class === ENTITY_MOB){
|
||||||
@ -157,6 +158,7 @@ class Level{
|
|||||||
$this->level->setData("time", (int) $this->time);
|
$this->level->setData("time", (int) $this->time);
|
||||||
$this->level->doSaveRound();
|
$this->level->doSaveRound();
|
||||||
$this->level->saveData();
|
$this->level->saveData();
|
||||||
|
$this->lastSave = microtime(true) + 90;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlock(Vector3 $pos){
|
public function getBlock(Vector3 $pos){
|
||||||
|
@ -34,7 +34,7 @@ class Position extends Vector3{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function distance($x = 0, $y = 0, $z = 0){
|
public function distance($x = 0, $y = 0, $z = 0){
|
||||||
if($x instanceof Position and $x->level !== $this->level){
|
if(($x instanceof Position) and $x->level !== $this->level){
|
||||||
return PHP_INT_MAX;
|
return PHP_INT_MAX;
|
||||||
}
|
}
|
||||||
return parent::distance($x, $y, $z);
|
return parent::distance($x, $y, $z);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user