Added SetDifficultyPacket

This commit is contained in:
Shoghi Cervantes 2014-11-06 19:07:24 +01:00
parent 1818e64c8e
commit 92143d523c
5 changed files with 58 additions and 0 deletions

View File

@ -94,6 +94,7 @@ use pocketmine\network\protocol\Info as ProtocolInfo;
use pocketmine\network\protocol\LoginStatusPacket;
use pocketmine\network\protocol\MessagePacket;
use pocketmine\network\protocol\MovePlayerPacket;
use pocketmine\network\protocol\SetDifficultyPacket;
use pocketmine\network\protocol\SetHealthPacket;
use pocketmine\network\protocol\SetSpawnPositionPacket;
use pocketmine\network\protocol\SetTimePacket;
@ -1447,6 +1448,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->dead = true;
}
$pk = new SetDifficultyPacket();
$pk->difficulty = $this->server->getDifficulty();
$this->dataPacket($pk);
$this->server->getLogger()->info(TextFormat::AQUA . $this->username . TextFormat::WHITE . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->id . " at (" . $this->level->getName() . ", " . round($this->x, 4) . ", " . round($this->y, 4) . ", " . round($this->z, 4) . ")");

View File

@ -22,6 +22,7 @@
namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\network\protocol\SetDifficultyPacket;
use pocketmine\Server;
use pocketmine\utils\TextFormat;
@ -55,6 +56,9 @@ class DifficultyCommand extends VanillaCommand{
if($difficulty !== -1){
$sender->getServer()->setConfigInt("difficulty", $difficulty);
$pk = new SetDifficultyPacket();
$pk->difficulty = $sender->getServer()->getDifficulty();
Server::broadcastPacket($sender->getServer()->getOnlinePlayers(), $pk);
$sender->sendMessage("Set difficulty to " . $difficulty);
}else{
$sender->sendMessage("Unknown difficulty");

View File

@ -60,6 +60,7 @@ use pocketmine\network\protocol\RemovePlayerPacket;
use pocketmine\network\protocol\RespawnPacket;
use pocketmine\network\protocol\RotateHeadPacket;
use pocketmine\network\protocol\SendInventoryPacket;
use pocketmine\network\protocol\SetDifficultyPacket;
use pocketmine\network\protocol\SetEntityDataPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\network\protocol\SetHealthPacket;
@ -328,6 +329,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{
$this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class);
$this->registerPacket(ProtocolInfo::ENTITY_DATA_PACKET, EntityDataPacket::class);
$this->registerPacket(ProtocolInfo::UNLOAD_CHUNK_PACKET, UnloadChunkPacket::class);
$this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class);
}
private function getPacket($buffer){

View File

@ -88,5 +88,6 @@ interface Info{
//const PLAYER_INPUT_PACKET = 0xb9;
const FULL_CHUNK_DATA_PACKET = 0xba;
const UNLOAD_CHUNK_PACKET = 0xbb;
const SET_DIFFICULTY_PACKET = 0xbc;
}

View File

@ -0,0 +1,46 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\network\protocol;
#include <rules/DataPacket.h>
class SetDifficultyPacket extends DataPacket{
public static $pool = [];
public static $next = 0;
public $difficulty;
public function pid(){
return Info::SET_DIFFICULTY_PACKET;
}
public function decode(){
$this->difficulty = $this->getInt();
}
public function encode(){
$this->reset();
$this->putInt($this->difficulty);
}
}