Adventure Mode

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-01 18:15:14 +01:00
parent eaa3006d51
commit d24d826ffd
5 changed files with 32 additions and 14 deletions

View File

@ -96,7 +96,7 @@ class BlockAPI{
return;
}
$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);
}
$drop = array(
@ -392,6 +392,10 @@ class BlockAPI{
if($cancelPlace === true){
return false;
}
if($this->server->gamemode === 2){
return $this->cancelAction($block);
}
$replace = false;
switch($data["block"]){

View File

@ -90,12 +90,12 @@ class ConsoleAPI{
break;
case "gamemode":
$s = trim(array_shift($params));
if($s == "" or (((int) $s) !== 0 and ((int) $s) !== 1)){
console("[INFO] Usage: /gamemode <0 | 1>");
if($s == "" or (((int) $s) !== 0 and ((int) $s) !== 1 and ((int) $s) !== 2)){
console("[INFO] Usage: /gamemode <0 | 1 | 2>");
break;
}
$this->server->api->setProperty("gamemode", (int) $s);
console("[INFO] Gamemode changed to ".$this->server->gamemode);
console("[INFO] Gamemode changed to ".$this->server->getGamemode());
break;
case "difficulty":
$s = trim(array_shift($params));

View File

@ -198,14 +198,14 @@ class Player{
}
break;
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);
}
break;
case "player.pickup":
if($data["eid"] === $this->eid){
$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);
}
}
@ -524,8 +524,11 @@ class Player{
0x20 nametags_visible
0x40 ?
0x80 ?
*/
*/
$flags = 0;
if($this->server->gamemode === 2){
$flags |= 0x01; //Not allow placing/breaking blocks
}
$flags |= 0x20; //Nametags
$this->dataPacket(MC_ADVENTURE_SETTINGS, array(
"flags" => $flags,
@ -576,7 +579,7 @@ class Player{
$data["eid"] = $this->eid;
if(Utils::distance($this->entity->position, $data) > 10){
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);
//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($this->handle("player.interact", $data) !== false){
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);
}
}

View File

@ -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] Time: \x1b[36m".$this->time."\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");
console("[INFO] Difficulty: \x1b[36m".$d[$this->difficulty]."\x1b[0m");
console("[INFO] Loading map...");
@ -292,7 +292,18 @@ class PocketMinecraftServer{
}else{
console("[INFO] Time: \x1b[36m".$this->time."\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],
$this->serverID,
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"]);
$this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description);
break;

View File

@ -136,7 +136,7 @@ class Entity extends stdClass{
$this->close(); //Despawn timer
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);
if($player !== true and $player !== false){
if($this->server->api->dhandle("player.pickup", array(
@ -486,7 +486,7 @@ class Entity extends stdClass{
if($health < $this->health){
$harm = true;
$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[1] = $dmg;
}else{