Skip to content

Commit

Permalink
Merge remote-tracking branch 'nethergames/stable' into stable
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
#	composer.lock
#	src/block/EnchantingTable.php
#	src/block/PressurePlate.php
#	src/block/utils/AgeableTrait.php
#	src/item/ItemTypeIds.php
#	src/item/enchantment/EnchantmentEntry.php
#	src/network/mcpe/handler/InGamePacketHandler.php
#	src/network/mcpe/handler/ItemStackRequestExecutor.php
#	src/network/mcpe/serializer/ChunkSerializer.php
  • Loading branch information
DavyCraft648 committed Sep 21, 2023
2 parents 7d08d0a + e8d891b commit 7e78050
Show file tree
Hide file tree
Showing 31 changed files with 267 additions and 834 deletions.
55 changes: 34 additions & 21 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
use pocketmine\utils\MainLogger;
use pocketmine\utils\NotCloneable;
use pocketmine\utils\NotSerializable;
use pocketmine\utils\ObjectSet;
use pocketmine\utils\Process;
use pocketmine\utils\SignalHandler;
use pocketmine\utils\Terminal;
Expand Down Expand Up @@ -307,7 +308,7 @@ class Server{
private array $packetSerializerContexts = [];
/** @var array<int, PacketBroadcaster> */
private array $packetBroadcasters = [];
/** @var array<int, EntityEventBroadcaster> */
/** @var array<string, EntityEventBroadcaster> */
private array $entityEventBroadcasters = [];

public function getName() : string{
Expand Down Expand Up @@ -566,7 +567,9 @@ public function saveOfflinePlayerData(string $name, CompoundTag $nbtTag) : void{
* @phpstan-return Promise<Player>
*/
public function createPlayer(NetworkSession $session, PlayerInfo $playerInfo, bool $authenticated, ?CompoundTag $offlinePlayerData) : Promise{
$ev = new PlayerCreationEvent($session);
/** @phpstan-var ObjectSet<Promise<null>> $promises */
$promises = new ObjectSet();
$ev = new PlayerCreationEvent($session, $promises);
$ev->call();
$class = $ev->getPlayerClass();

Expand All @@ -583,32 +586,42 @@ public function createPlayer(NetworkSession $session, PlayerInfo $playerInfo, bo
$playerPromiseResolver = new PromiseResolver();

$createPlayer = function(Location $location) use ($playerPromiseResolver, $class, $session, $playerInfo, $authenticated, $offlinePlayerData) : void{
if(!$session->isConnected()){
$playerPromiseResolver->reject();
return;
}

$player = new $class($this, $session, $playerInfo, $authenticated, $location, $offlinePlayerData);
if(!$player->hasPlayedBefore()){
$player->onGround = true; //TODO: this hack is needed for new players in-air ticks - they don't get detected as on-ground until they move
}
$playerPromiseResolver->resolve($player);
};

if($playerPos === null){ //new player or no valid position due to world not being loaded
$world->requestSafeSpawn()->onCompletion(
function(Position $spawn) use ($createPlayer, $playerPromiseResolver, $session, $world) : void{
if(!$session->isConnected()){
$playerPromiseResolver->reject();
return;
}
$createPlayer(Location::fromObject($spawn, $world));
},
function() use ($playerPromiseResolver, $session) : void{
if($session->isConnected()){
$session->disconnectWithError(KnownTranslationFactory::pocketmine_disconnect_error_respawn());
$playerCreationRejected = function (Translatable|string $message) use ($playerPromiseResolver, $session) : void{
if($session->isConnected()){
$session->disconnectWithError($message);
}
$playerPromiseResolver->reject();
};

$promise = Promise::all($promises->toArray());
$promise->onCompletion(function () use ($playerPos, $world, $createPlayer, $playerCreationRejected) : void{
if($playerPos === null){ //new player or no valid position due to world not being loaded
$world->requestSafeSpawn()->onCompletion(
function(Position $spawn) use ($createPlayer, $world) : void{
$createPlayer(Location::fromObject($spawn, $world));
},
function() use ($playerCreationRejected) : void{
$playerCreationRejected(KnownTranslationFactory::pocketmine_disconnect_error_respawn());
}
$playerPromiseResolver->reject();
}
);
}else{ //returning player with a valid position - safe spawn not required
$createPlayer($playerPos);
}
);
}else{ //returning player with a valid position - safe spawn not required
$createPlayer($playerPos);
}
}, function () use ($playerCreationRejected) : void{
$playerCreationRejected("Failed to create player");
});

return $playerPromiseResolver->getPromise();
}
Expand Down Expand Up @@ -1882,6 +1895,6 @@ public function getPacketBroadcaster(PacketSerializerContext $packetSerializerCo
return $this->packetBroadcasters[spl_object_id($packetSerializerContext)] ??= new StandardPacketBroadcaster($this, $packetSerializerContext);
}
public function getEntityEventBroadcaster(PacketBroadcaster $packetBroadcaster, TypeConverter $typeConverter) : EntityEventBroadcaster{
return $this->entityEventBroadcasters[spl_object_id($typeConverter)] ??= new StandardEntityEventBroadcaster($packetBroadcaster, $typeConverter);
return $this->entityEventBroadcasters[spl_object_id($packetBroadcaster) . ':' . spl_object_id($typeConverter)] ??= new StandardEntityEventBroadcaster($packetBroadcaster, $typeConverter);
}
}
81 changes: 0 additions & 81 deletions src/block/utils/HorizontalFacing8.php

This file was deleted.

40 changes: 5 additions & 35 deletions src/data/bedrock/BedrockDataFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,14 @@ private function __construct(){
public const BIOME_DEFINITIONS_NBT = BEDROCK_DATA_PATH . '/biome_definitions.nbt';
public const BIOME_DEFINITIONS_FULL_NBT = BEDROCK_DATA_PATH . '/biome_definitions_full.nbt';
public const BIOME_ID_MAP_JSON = BEDROCK_DATA_PATH . '/biome_id_map.json';
public const BLOCK_ID_TO_ITEM_ID_MAP_1_18_10_JSON = BEDROCK_DATA_PATH . '/block_id_to_item_id_map-1.18.10.json';
public const BLOCK_ID_TO_ITEM_ID_MAP_1_18_30_JSON = BEDROCK_DATA_PATH . '/block_id_to_item_id_map-1.18.30.json';
public const BLOCK_ID_TO_ITEM_ID_MAP_1_19_0_JSON = BEDROCK_DATA_PATH . '/block_id_to_item_id_map-1.19.0.json';
public const BLOCK_ID_TO_ITEM_ID_MAP_1_19_40_JSON = BEDROCK_DATA_PATH . '/block_id_to_item_id_map-1.19.40.json';
public const BLOCK_ID_TO_ITEM_ID_MAP_1_19_50_JSON = BEDROCK_DATA_PATH . '/block_id_to_item_id_map-1.19.50.json';
public const BLOCK_ID_TO_ITEM_ID_MAP_1_19_63_JSON = BEDROCK_DATA_PATH . '/block_id_to_item_id_map-1.19.63.json';
public const BLOCK_ID_TO_ITEM_ID_MAP_1_19_70_JSON = BEDROCK_DATA_PATH . '/block_id_to_item_id_map-1.19.70.json';
public const BLOCK_ID_TO_ITEM_ID_MAP_1_19_80_JSON = BEDROCK_DATA_PATH . '/block_id_to_item_id_map-1.19.80.json';
public const BLOCK_ID_TO_ITEM_ID_MAP_1_20_0_JSON = BEDROCK_DATA_PATH . '/block_id_to_item_id_map-1.20.0.json';
public const BLOCK_ID_TO_ITEM_ID_MAP_1_20_10_JSON = BEDROCK_DATA_PATH . '/block_id_to_item_id_map-1.20.10.json';
public const BLOCK_ID_TO_ITEM_ID_MAP_JSON = BEDROCK_DATA_PATH . '/block_id_to_item_id_map.json';
public const BLOCK_STATE_META_MAP_1_19_10_JSON = BEDROCK_DATA_PATH . '/block_state_meta_map-1.19.10.json';
public const BLOCK_STATE_META_MAP_1_19_40_JSON = BEDROCK_DATA_PATH . '/block_state_meta_map-1.19.40.json';
public const BLOCK_STATE_META_MAP_1_19_50_JSON = BEDROCK_DATA_PATH . '/block_state_meta_map-1.19.50.json';
public const BLOCK_STATE_META_MAP_1_19_63_JSON = BEDROCK_DATA_PATH . '/block_state_meta_map-1.19.63.json';
public const BLOCK_STATE_META_MAP_1_19_70_JSON = BEDROCK_DATA_PATH . '/block_state_meta_map-1.19.70.json';
public const BLOCK_STATE_META_MAP_1_19_80_JSON = BEDROCK_DATA_PATH . '/block_state_meta_map-1.19.80.json';
public const BLOCK_STATE_META_MAP_1_20_0_JSON = BEDROCK_DATA_PATH . '/block_state_meta_map-1.20.0.json';
public const BLOCK_STATE_META_MAP_1_20_10_JSON = BEDROCK_DATA_PATH . '/block_state_meta_map-1.20.10.json';
public const BLOCK_STATE_META_MAP_JSON = BEDROCK_DATA_PATH . '/block_state_meta_map.json';
public const CANONICAL_BLOCK_STATES_1_18_10_NBT = BEDROCK_DATA_PATH . '/canonical_block_states-1.18.10.nbt';
public const CANONICAL_BLOCK_STATES_1_18_30_NBT = BEDROCK_DATA_PATH . '/canonical_block_states-1.18.30.nbt';
public const CANONICAL_BLOCK_STATES_1_19_10_NBT = BEDROCK_DATA_PATH . '/canonical_block_states-1.19.10.nbt';
public const CANONICAL_BLOCK_STATES_1_19_40_NBT = BEDROCK_DATA_PATH . '/canonical_block_states-1.19.40.nbt';
public const CANONICAL_BLOCK_STATES_1_19_50_NBT = BEDROCK_DATA_PATH . '/canonical_block_states-1.19.50.nbt';
public const CANONICAL_BLOCK_STATES_1_19_63_NBT = BEDROCK_DATA_PATH . '/canonical_block_states-1.19.63.nbt';
public const CANONICAL_BLOCK_STATES_1_19_70_NBT = BEDROCK_DATA_PATH . '/canonical_block_states-1.19.70.nbt';
public const CANONICAL_BLOCK_STATES_1_19_80_NBT = BEDROCK_DATA_PATH . '/canonical_block_states-1.19.80.nbt';
public const CANONICAL_BLOCK_STATES_1_20_0_NBT = BEDROCK_DATA_PATH . '/canonical_block_states-1.20.0.nbt';
public const CANONICAL_BLOCK_STATES_1_20_10_NBT = BEDROCK_DATA_PATH . '/canonical_block_states-1.20.10.nbt';
public const CANONICAL_BLOCK_STATES_NBT = BEDROCK_DATA_PATH . '/canonical_block_states.nbt';
public const COMMAND_ARG_TYPES_JSON = BEDROCK_DATA_PATH . '/command_arg_types.json';
public const CREATIVEITEMS_JSON = BEDROCK_DATA_PATH . '/creativeitems.json';
Expand All @@ -69,22 +50,11 @@ private function __construct(){
public const ITEM_TAGS_JSON = BEDROCK_DATA_PATH . '/item_tags.json';
public const LEVEL_SOUND_ID_MAP_JSON = BEDROCK_DATA_PATH . '/level_sound_id_map.json';
public const PARTICLE_ID_MAP_JSON = BEDROCK_DATA_PATH . '/particle_id_map.json';
public const R12_TO_CURRENT_BLOCK_MAP_1_18_10_BIN = BEDROCK_DATA_PATH . '/r12_to_current_block_map-1.18.10.bin';
public const R12_TO_CURRENT_BLOCK_MAP_1_18_30_BIN = BEDROCK_DATA_PATH . '/r12_to_current_block_map-1.18.30.bin';
public const R12_TO_CURRENT_BLOCK_MAP_1_19_63_BIN = BEDROCK_DATA_PATH . '/r12_to_current_block_map-1.19.63.bin';
public const R12_TO_CURRENT_BLOCK_MAP_1_19_70_BIN = BEDROCK_DATA_PATH . '/r12_to_current_block_map-1.19.70.bin';
public const R12_TO_CURRENT_BLOCK_MAP_1_19_80_BIN = BEDROCK_DATA_PATH . '/r12_to_current_block_map-1.19.80.bin';
public const R12_TO_CURRENT_BLOCK_MAP_1_20_0_BIN = BEDROCK_DATA_PATH . '/r12_to_current_block_map-1.20.0.bin';
public const R12_TO_CURRENT_BLOCK_MAP_1_20_10_BIN = BEDROCK_DATA_PATH . '/r12_to_current_block_map-1.20.10.bin';
public const R12_TO_CURRENT_BLOCK_MAP_BIN = BEDROCK_DATA_PATH . '/r12_to_current_block_map.bin';
public const R16_TO_CURRENT_ITEM_MAP_JSON = BEDROCK_DATA_PATH . '/r16_to_current_item_map.json';
public const REQUIRED_ITEM_LIST_1_18_10_JSON = BEDROCK_DATA_PATH . '/required_item_list-1.18.10.json';
public const REQUIRED_ITEM_LIST_1_18_30_JSON = BEDROCK_DATA_PATH . '/required_item_list-1.18.30.json';
public const REQUIRED_ITEM_LIST_1_19_0_JSON = BEDROCK_DATA_PATH . '/required_item_list-1.19.0.json';
public const REQUIRED_ITEM_LIST_1_19_40_JSON = BEDROCK_DATA_PATH . '/required_item_list-1.19.40.json';
public const REQUIRED_ITEM_LIST_1_19_50_JSON = BEDROCK_DATA_PATH . '/required_item_list-1.19.50.json';
public const REQUIRED_ITEM_LIST_1_19_63_JSON = BEDROCK_DATA_PATH . '/required_item_list-1.19.63.json';
public const REQUIRED_ITEM_LIST_1_19_70_JSON = BEDROCK_DATA_PATH . '/required_item_list-1.19.70.json';
public const REQUIRED_ITEM_LIST_1_19_80_JSON = BEDROCK_DATA_PATH . '/required_item_list-1.19.80.json';
public const REQUIRED_ITEM_LIST_1_20_0_JSON = BEDROCK_DATA_PATH . '/required_item_list-1.20.0.json';
public const REQUIRED_ITEM_LIST_1_20_10_JSON = BEDROCK_DATA_PATH . '/required_item_list-1.20.10.json';
public const REQUIRED_ITEM_LIST_JSON = BEDROCK_DATA_PATH . '/required_item_list.json';
}
2 changes: 1 addition & 1 deletion src/entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ protected function entityBaseTick(int $tickDiff = 1) : bool{
}
$this->checkBlockIntersectionsNextTick = true;

if($this->location->y <= World::Y_MIN - 16 && $this->isAlive()){
if($this->location->y <= 0 && $this->isAlive()){
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10);
$this->attack($ev);
$hasUpdate = true;
Expand Down
14 changes: 0 additions & 14 deletions src/entity/Human.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\PlayerSkinPacket;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\network\mcpe\protocol\types\AbilitiesData;
use pocketmine\network\mcpe\protocol\types\AbilitiesLayer;
use pocketmine\network\mcpe\protocol\types\command\CommandPermissions;
Expand All @@ -71,7 +70,6 @@
use pocketmine\world\sound\TotemUseSound;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use function array_diff;
use function array_fill;
use function array_filter;
use function array_key_exists;
Expand Down Expand Up @@ -166,10 +164,6 @@ public function setSkin(Skin $skin) : void{
* @param Player[]|null $targets
*/
public function sendSkin(?array $targets = null) : void{
if($this instanceof Player && $this->getNetworkSession()->getProtocolId() === ProtocolInfo::PROTOCOL_1_19_60){
$targets = array_diff($targets ?? $this->hasSpawned, [$this]);
}

TypeConverter::broadcastByTypeConverter($targets ?? $this->hasSpawned, function(TypeConverter $typeConverter) : array{
return [
PlayerSkinPacket::create($this->getUniqueId(), "", "", $typeConverter->getSkinAdapter()->toSkinData($this->skin))
Expand Down Expand Up @@ -246,14 +240,6 @@ public function getEnderInventory() : PlayerEnderInventory{
return $this->enderInventory;
}

public function getXpSeed() : int{
return $this->xpSeed;
}

public function setXpSeed(int $xpSeed) : void{
$this->xpSeed = $xpSeed;
}

/**
* For Human entities which are not players, sets their properties such as nametag, skin and UUID from NBT.
*/
Expand Down
1 change: 1 addition & 0 deletions src/entity/projectile/SplashPotion.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use pocketmine\event\entity\ProjectileHitBlockEvent;
use pocketmine\event\entity\ProjectileHitEntityEvent;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\item\Potion;
use pocketmine\item\PotionType;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
Expand Down
21 changes: 20 additions & 1 deletion src/event/player/PlayerCreationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
use pocketmine\event\Event;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\player\Player;
use pocketmine\promise\Promise;
use pocketmine\utils\ObjectSet;
use pocketmine\utils\Utils;
use function is_a;

/**
* Allows the use of custom Player classes. This enables overriding built-in Player methods to change behaviour that is
* not possible to alter any other way.
*
* Allows the plugins to specify promise that need to be completed before the login sequence take place.
*
* You probably don't need this event, and found your way here because you looked at some code in an old plugin that
* abused it (very common). Instead of using custom player classes, you should consider making session classes instead.
*
Expand All @@ -52,7 +56,11 @@ class PlayerCreationEvent extends Event{
/** @phpstan-var class-string<Player> */
private string $playerClass = Player::class;

public function __construct(private NetworkSession $session){}
/** @phpstan-param ObjectSet<Promise<null>> $promises */
public function __construct(
private NetworkSession $session,
private ObjectSet $promises
){}

public function getNetworkSession() : NetworkSession{
return $this->session;
Expand Down Expand Up @@ -109,4 +117,15 @@ public function setPlayerClass(string $class) : void{
Utils::testValidInstance($class, $this->baseClass);
$this->playerClass = $class;
}

/**
* Adds a promise to the waiting list for the login sequence.
* Once all the promises that have been added have been completed,
* the player login sequence will be initiated and the player will be created.
*
* @phpstan-param Promise<null> $promise
*/
public function addPromise(Promise $promise) : void{
$this->promises->add($promise);
}
}
Empty file removed src/item/ItemFactory.php
Empty file.
Loading

0 comments on commit 7e78050

Please sign in to comment.