More broken mess to spawn 1.2

This commit is contained in:
Dylan K. Taylor
2017-08-01 20:06:02 +01:00
parent 10ff2948ac
commit 77cd8e7799
52 changed files with 1558 additions and 506 deletions

View File

@ -115,9 +115,7 @@ use pocketmine\network\mcpe\protocol\BossEventPacket;
use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket;
use pocketmine\network\mcpe\protocol\ClientToServerHandshakePacket;
use pocketmine\network\mcpe\protocol\CommandBlockUpdatePacket;
use pocketmine\network\mcpe\protocol\CommandStepPacket;
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
use pocketmine\network\mcpe\protocol\ContainerSetContentPacket;
use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket;
use pocketmine\network\mcpe\protocol\CraftingEventPacket;
use pocketmine\network\mcpe\protocol\DataPacket;
@ -156,6 +154,7 @@ use pocketmine\network\mcpe\protocol\TextPacket;
use pocketmine\network\mcpe\protocol\TransferPacket;
use pocketmine\network\mcpe\protocol\types\ContainerIds;
use pocketmine\network\mcpe\protocol\types\DimensionIds;
use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
use pocketmine\network\mcpe\protocol\UpdateAttributesPacket;
use pocketmine\network\mcpe\protocol\UpdateBlockPacket;
use pocketmine\network\mcpe\protocol\UseItemPacket;
@ -1321,14 +1320,17 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
*/
public function sendSettings(){
$pk = new AdventureSettingsPacket();
$pk->flags = 0;
$pk->worldImmutable = $this->isSpectator();
$pk->noPvp = $this->isSpectator();
$pk->autoJump = $this->autoJump;
$pk->allowFlight = $this->allowFlight;
$pk->noClip = $this->isSpectator();
$pk->isFlying = $this->flying;
$pk->userPermission = ($this->isOp() ? AdventureSettingsPacket::PERMISSION_OPERATOR : AdventureSettingsPacket::PERMISSION_NORMAL);
$pk->setFlag(AdventureSettingsPacket::WORLD_IMMUTABLE, $this->isSpectator());
$pk->setFlag(AdventureSettingsPacket::NO_PVP, $this->isSpectator());
$pk->setFlag(AdventureSettingsPacket::AUTO_JUMP, $this->autoJump);
$pk->setFlag(AdventureSettingsPacket::ALLOW_FLIGHT, $this->allowFlight);
$pk->setFlag(AdventureSettingsPacket::NO_CLIP, $this->isSpectator());
$pk->setFlag(AdventureSettingsPacket::FLYING, $this->flying);
$pk->commandPermission = ($this->isOp() ? AdventureSettingsPacket::PERMISSION_OPERATOR : AdventureSettingsPacket::PERMISSION_NORMAL);
$pk->playerPermission = ($this->isOp() ? PlayerPermissions::OPERATOR : PlayerPermissions::MEMBER);
$this->dataPacket($pk);
}
@ -1864,7 +1866,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$pk->spawnY = $spawnPosition->getFloorY();
$pk->spawnZ = $spawnPosition->getFloorZ();
$pk->hasAchievementsDisabled = true;
$pk->dayCycleStopTime = -1; //TODO: implement this properly
$pk->time = $this->level->getTime();
$pk->eduMode = false;
$pk->rainLevel = 0; //TODO: implement these properly
$pk->lightningLevel = 0;
@ -2029,40 +2031,40 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return true;
}
public function handleText(TextPacket $packet) : bool{
/**
* Sends a chat message as this player. If the message begins with a / (forward-slash) it will be treated
* as a command.
*
* @param string $message
*
* @return bool
*/
public function chat(string $message) : bool{
if($this->spawned === false or !$this->isAlive()){
return true;
return false;
}
$this->craftingType = 0;
if($packet->type === TextPacket::TYPE_CHAT){
$packet->message = TextFormat::clean($packet->message, $this->removeFormat);
foreach(explode("\n", $packet->message) as $message){
if(trim($message) != "" and strlen($message) <= 255 and $this->messageCounter-- > 0){
if(substr($message, 0, 2) === "./"){ //Command (./ = fast hack for old plugins post 0.16)
$message = substr($message, 1);
}
$ev = new PlayerCommandPreprocessEvent($this, $message);
$message = TextFormat::clean($message, $this->removeFormat);
foreach(explode("\n", $message) as $messagePart){
if(trim($messagePart) !== "" and strlen($messagePart) <= 255 and $this->messageCounter-- > 0){
$ev = new PlayerCommandPreprocessEvent($this, $message);
if(mb_strlen($ev->getMessage(), "UTF-8") > 320){
$ev->setCancelled();
}
$this->server->getPluginManager()->callEvent($ev);
$this->server->getPluginManager()->callEvent($ev);
if($ev->isCancelled()){
break;
}
if($ev->isCancelled()){
break;
}
if(substr($ev->getMessage(), 0, 1) === "/"){
Timings::$playerCommandTimer->startTiming();
$this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1));
Timings::$playerCommandTimer->stopTiming();
}else{
$this->server->getPluginManager()->callEvent($ev = new PlayerChatEvent($this, $ev->getMessage()));
if(!$ev->isCancelled()){
$this->server->broadcastMessage($this->getServer()->getLanguage()->translateString($ev->getFormat(), [$ev->getPlayer()->getDisplayName(), $ev->getMessage()]), $ev->getRecipients());
}
if(strpos($ev->getMessage(), "/") === 0){
Timings::$playerCommandTimer->startTiming();
$this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1));
Timings::$playerCommandTimer->stopTiming();
}else{
$this->server->getPluginManager()->callEvent($ev = new PlayerChatEvent($this, $ev->getMessage()));
if(!$ev->isCancelled()){
$this->server->broadcastMessage($this->getServer()->getLanguage()->translateString($ev->getFormat(), [$ev->getPlayer()->getDisplayName(), $ev->getMessage()]), $ev->getRecipients());
}
}
}
@ -2475,7 +2477,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
public function handlePlayerAction(PlayerActionPacket $packet) : bool{
if($this->spawned === false or (!$this->isAlive() and $packet->action !== PlayerActionPacket::ACTION_RESPAWN and $packet->action !== PlayerActionPacket::ACTION_DIMENSION_CHANGE)){
if($this->spawned === false or (!$this->isAlive() and $packet->action !== PlayerActionPacket::ACTION_RESPAWN and $packet->action !== PlayerActionPacket::ACTION_DIMENSION_CHANGE_REQUEST)){
return true;
}
@ -3033,11 +3035,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{
if($packet->isFlying and !$this->allowFlight and !$this->server->getAllowFlight()){
$isFlying = $packet->getFlag(AdventureSettingsPacket::FLYING);
if($isFlying and !$this->allowFlight and !$this->server->getAllowFlight()){
$this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"]));
return true;
}elseif($packet->isFlying !== $this->isFlying()){
$this->server->getPluginManager()->callEvent($ev = new PlayerToggleFlightEvent($this, $packet->isFlying));
}elseif($isFlying !== $this->isFlying()){
$this->server->getPluginManager()->callEvent($ev = new PlayerToggleFlightEvent($this, $isFlying));
if($ev->isCancelled()){
$this->sendSettings();
}else{
@ -3045,7 +3048,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
}
if($packet->noClip and !$this->allowMovementCheats and !$this->isSpectator()){
if($packet->getFlag(AdventureSettingsPacket::NO_CLIP) and !$this->allowMovementCheats and !$this->isSpectator()){
$this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.noclip"]));
return true;
}
@ -3143,29 +3146,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return false; //TODO: handle resume
}
public function handleCommandStep(CommandStepPacket $packet) : bool{
if($this->spawned === false or !$this->isAlive()){
return true;
}
$this->craftingType = 0;
$commandText = $packet->command;
if($packet->inputJson !== null){
foreach($packet->inputJson as $arg){ //command ordering will be an issue
$commandText .= " " . $arg;
}
}
$this->server->getPluginManager()->callEvent($ev = new PlayerCommandPreprocessEvent($this, "/" . $commandText));
if($ev->isCancelled()){
return true;
}
Timings::$playerCommandTimer->startTiming();
$this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1));
Timings::$playerCommandTimer->stopTiming();
return true;
}
public function handleCommandBlockUpdate(CommandBlockUpdatePacket $packet) : bool{
return false; //TODO
}