mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +00:00
Adventure Mode
This commit is contained in:
parent
eaa3006d51
commit
d24d826ffd
@ -96,7 +96,7 @@ class BlockAPI{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$target = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
|
$target = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
|
||||||
if(isset(Material::$unbreakable[$target[0]])){
|
if(isset(Material::$unbreakable[$target[0]]) or $this->server->gamemode === 2){
|
||||||
return $this->cancelAction($target);
|
return $this->cancelAction($target);
|
||||||
}
|
}
|
||||||
$drop = array(
|
$drop = array(
|
||||||
@ -393,6 +393,10 @@ class BlockAPI{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->server->gamemode === 2){
|
||||||
|
return $this->cancelAction($block);
|
||||||
|
}
|
||||||
|
|
||||||
$replace = false;
|
$replace = false;
|
||||||
switch($data["block"]){
|
switch($data["block"]){
|
||||||
case 44: //Slabs
|
case 44: //Slabs
|
||||||
|
@ -90,12 +90,12 @@ class ConsoleAPI{
|
|||||||
break;
|
break;
|
||||||
case "gamemode":
|
case "gamemode":
|
||||||
$s = trim(array_shift($params));
|
$s = trim(array_shift($params));
|
||||||
if($s == "" or (((int) $s) !== 0 and ((int) $s) !== 1)){
|
if($s == "" or (((int) $s) !== 0 and ((int) $s) !== 1 and ((int) $s) !== 2)){
|
||||||
console("[INFO] Usage: /gamemode <0 | 1>");
|
console("[INFO] Usage: /gamemode <0 | 1 | 2>");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->server->api->setProperty("gamemode", (int) $s);
|
$this->server->api->setProperty("gamemode", (int) $s);
|
||||||
console("[INFO] Gamemode changed to ".$this->server->gamemode);
|
console("[INFO] Gamemode changed to ".$this->server->getGamemode());
|
||||||
break;
|
break;
|
||||||
case "difficulty":
|
case "difficulty":
|
||||||
$s = trim(array_shift($params));
|
$s = trim(array_shift($params));
|
||||||
|
@ -198,14 +198,14 @@ class Player{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "player.block.place":
|
case "player.block.place":
|
||||||
if($data["eid"] === $this->eid and $this->server->gamemode === 0){
|
if($data["eid"] === $this->eid and ($this->server->gamemode === 0 or $this->server->gamemode === 2)){
|
||||||
$this->removeItem($data["original"][0], $data["original"][1], 1);
|
$this->removeItem($data["original"][0], $data["original"][1], 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "player.pickup":
|
case "player.pickup":
|
||||||
if($data["eid"] === $this->eid){
|
if($data["eid"] === $this->eid){
|
||||||
$data["eid"] = 0;
|
$data["eid"] = 0;
|
||||||
if($this->server->gamemode === 0){
|
if(($this->server->gamemode === 0 or $this->server->gamemode === 2)){
|
||||||
$this->addItem($data["entity"]->type, $data["entity"]->meta, $data["entity"]->stack);
|
$this->addItem($data["entity"]->type, $data["entity"]->meta, $data["entity"]->stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -526,6 +526,9 @@ class Player{
|
|||||||
0x80 ?
|
0x80 ?
|
||||||
*/
|
*/
|
||||||
$flags = 0;
|
$flags = 0;
|
||||||
|
if($this->server->gamemode === 2){
|
||||||
|
$flags |= 0x01; //Not allow placing/breaking blocks
|
||||||
|
}
|
||||||
$flags |= 0x20; //Nametags
|
$flags |= 0x20; //Nametags
|
||||||
$this->dataPacket(MC_ADVENTURE_SETTINGS, array(
|
$this->dataPacket(MC_ADVENTURE_SETTINGS, array(
|
||||||
"flags" => $flags,
|
"flags" => $flags,
|
||||||
@ -576,7 +579,7 @@ class Player{
|
|||||||
$data["eid"] = $this->eid;
|
$data["eid"] = $this->eid;
|
||||||
if(Utils::distance($this->entity->position, $data) > 10){
|
if(Utils::distance($this->entity->position, $data) > 10){
|
||||||
break;
|
break;
|
||||||
}elseif($this->server->gamemode === 0 and !$this->hasItem($data["block"], $data["meta"])){
|
}elseif(($this->server->gamemode === 0 or $this->server->gamemode === 2) and !$this->hasItem($data["block"], $data["meta"])){
|
||||||
console("[DEBUG] Player \"".$this->username."\" tried to place not got block (or crafted block)", true, true, 2);
|
console("[DEBUG] Player \"".$this->username."\" tried to place not got block (or crafted block)", true, true, 2);
|
||||||
//break;
|
//break;
|
||||||
}
|
}
|
||||||
@ -597,7 +600,7 @@ class Player{
|
|||||||
if(isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){
|
if(isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){
|
||||||
if($this->handle("player.interact", $data) !== false){
|
if($this->handle("player.interact", $data) !== false){
|
||||||
console("[DEBUG] EID ".$this->eid." attacked EID ".$data["target"], true, true, 2);
|
console("[DEBUG] EID ".$this->eid." attacked EID ".$data["target"], true, true, 2);
|
||||||
if($this->server->gamemode !== 1 and $this->server->difficulty > 0){
|
if($this->server->difficulty > 0){
|
||||||
$this->server->api->entity->harm($data["target"], $this->server->difficulty, $this->eid);
|
$this->server->api->entity->harm($data["target"], $this->server->difficulty, $this->eid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ class PocketMinecraftServer{
|
|||||||
console("[INFO] Spawn: X \x1b[36m".$this->levelData["SpawnX"]."\x1b[0m Y \x1b[36m".$this->levelData["SpawnY"]."\x1b[0m Z \x1b[36m".$this->levelData["SpawnZ"]."\x1b[0m");
|
console("[INFO] Spawn: X \x1b[36m".$this->levelData["SpawnX"]."\x1b[0m Y \x1b[36m".$this->levelData["SpawnY"]."\x1b[0m Z \x1b[36m".$this->levelData["SpawnZ"]."\x1b[0m");
|
||||||
console("[INFO] Time: \x1b[36m".$this->time."\x1b[0m");
|
console("[INFO] Time: \x1b[36m".$this->time."\x1b[0m");
|
||||||
console("[INFO] Seed: \x1b[36m".$this->seed."\x1b[0m");
|
console("[INFO] Seed: \x1b[36m".$this->seed."\x1b[0m");
|
||||||
console("[INFO] Gamemode: \x1b[36m".($this->gamemode === 0 ? "survival":"creative")."\x1b[0m");
|
console("[INFO] Gamemode: \x1b[36m".$this->getGamemode()."\x1b[0m");
|
||||||
$d = array(0 => "peaceful", 1 => "easy", 2 => "normal", 3 => "hard");
|
$d = array(0 => "peaceful", 1 => "easy", 2 => "normal", 3 => "hard");
|
||||||
console("[INFO] Difficulty: \x1b[36m".$d[$this->difficulty]."\x1b[0m");
|
console("[INFO] Difficulty: \x1b[36m".$d[$this->difficulty]."\x1b[0m");
|
||||||
console("[INFO] Loading map...");
|
console("[INFO] Loading map...");
|
||||||
@ -292,7 +292,18 @@ class PocketMinecraftServer{
|
|||||||
}else{
|
}else{
|
||||||
console("[INFO] Time: \x1b[36m".$this->time."\x1b[0m");
|
console("[INFO] Time: \x1b[36m".$this->time."\x1b[0m");
|
||||||
console("[INFO] Seed: \x1b[36m".$this->seed."\x1b[0m");
|
console("[INFO] Seed: \x1b[36m".$this->seed."\x1b[0m");
|
||||||
console("[INFO] Gamemode: \x1b[36m".($this->gamemode === 0 ? "survival":"creative")."\x1b[0m");
|
console("[INFO] Gamemode: \x1b[36m".$this->getGamemode()."\x1b[0m");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGamemode(){
|
||||||
|
switch($this->gamemode){
|
||||||
|
case 0:
|
||||||
|
return "survival";
|
||||||
|
case 1:
|
||||||
|
return "creative";
|
||||||
|
case 2:
|
||||||
|
return "adventure";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,7 +519,7 @@ class PocketMinecraftServer{
|
|||||||
$data[0],
|
$data[0],
|
||||||
$this->serverID,
|
$this->serverID,
|
||||||
MAGIC,
|
MAGIC,
|
||||||
$this->serverType. $this->name . " [".($this->gamemode === 1 ? "C":"S").($this->whitelist !== false ? "W":"")." ".count($this->clients)."/".$this->maxClients."] ".$txt,
|
$this->serverType. $this->name . " [".($this->gamemode === 1 ? "C":($this->gamemode === 2 ? "A":"S")).($this->whitelist !== false ? "W":"")." ".count($this->clients)."/".$this->maxClients."] ".$txt,
|
||||||
), false, $packet["ip"], $packet["port"]);
|
), false, $packet["ip"], $packet["port"]);
|
||||||
$this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description);
|
$this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description);
|
||||||
break;
|
break;
|
||||||
|
@ -136,7 +136,7 @@ class Entity extends stdClass{
|
|||||||
$this->close(); //Despawn timer
|
$this->close(); //Despawn timer
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($this->server->gamemode === 0 and ($time - $this->spawntime) >= 2){
|
if(($this->server->gamemode === 0 or $this->server->gamemode === 2) and ($time - $this->spawntime) >= 2){
|
||||||
$player = $this->server->query("SELECT EID FROM entities WHERE class == ".ENTITY_PLAYER." AND abs(x - {$this->x}) <= 1.5 AND abs(y - {$this->y}) <= 1.5 AND abs(z - {$this->z}) <= 1.5 LIMIT 1;", true);
|
$player = $this->server->query("SELECT EID FROM entities WHERE class == ".ENTITY_PLAYER." AND abs(x - {$this->x}) <= 1.5 AND abs(y - {$this->y}) <= 1.5 AND abs(z - {$this->z}) <= 1.5 LIMIT 1;", true);
|
||||||
if($player !== true and $player !== false){
|
if($player !== true and $player !== false){
|
||||||
if($this->server->api->dhandle("player.pickup", array(
|
if($this->server->api->dhandle("player.pickup", array(
|
||||||
@ -486,7 +486,7 @@ class Entity extends stdClass{
|
|||||||
if($health < $this->health){
|
if($health < $this->health){
|
||||||
$harm = true;
|
$harm = true;
|
||||||
$dmg = $this->health - $health;
|
$dmg = $this->health - $health;
|
||||||
if(($this->server->gamemode === 0 or $force === true) and ($this->dmgcounter[0] < microtime(true) or $this->dmgcounter[1] < $dmg) and !$this->dead){
|
if(($this->server->gamemode === 0 or $this->server->gamemode === 2 or $force === true or $this->class !== ENTITY_PLAYER) and ($this->dmgcounter[0] < microtime(true) or $this->dmgcounter[1] < $dmg) and !$this->dead){
|
||||||
$this->dmgcounter[0] = microtime(true) + 0.5;
|
$this->dmgcounter[0] = microtime(true) + 0.5;
|
||||||
$this->dmgcounter[1] = $dmg;
|
$this->dmgcounter[1] = $dmg;
|
||||||
}else{
|
}else{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user