コード例 #1
0
void CustomServerNetworkHandler::handleBlockEntityData(ServerNetworkHandler *real, const RakNet::RakNetGUID &guid, BlockEntityDataPacket *packet)
{
	Player *player = real->_getPlayer(guid);
	if (!player)
		return;

	SMPlayer *smPlayer = ServerManager::getServer()->getPlayer(player);
	if (smPlayer->isLocalPlayer())
		return;

	BlockEntity *blockEntity = player->getRegion()->getBlockEntity(packet->pos);
	if (!blockEntity)
		return;

	if (BlockEntity::isType(*blockEntity, BlockEntityType::SIGN) && !packet->dataTag.getString("id").compare("Sign"))
	{
		SignChangeEvent event(player->getRegion()->getBlock(packet->pos), smPlayer, {
			packet->dataTag.getString("Text1"),
			packet->dataTag.getString("Text2"),
			packet->dataTag.getString("Text3"),
			packet->dataTag.getString("Text4")
		});
		ServerManager::getPluginManager()->callEvent(event);

		if (!event.isCancelled())
		{
			blockEntity->onUpdatePacket(packet->dataTag);
			player->getRegion()->getDimension()->sendBroadcast(*packet, player);
		}
	}
}
コード例 #2
0
void CustomServerNetworkHandler::handleAnimate(ServerNetworkHandler *real, const RakNet::RakNetGUID &guid, AnimatePacket *packet)
{
	Player *player = real->_getPlayer(guid, packet->uniqueID);
	if (!player || !player->isAlive())
		return;

	SMPlayer *smPlayer = ServerManager::getServer()->getPlayer(player);
	if (smPlayer->isLocalPlayer())
		return;

	PlayerAnimationEvent event(smPlayer, (PlayerAnimationType)packet->action);
	ServerManager::getPluginManager()->callEvent(event);

	if (event.isCancelled())
		return;

	handleAnimate_real(real, guid, packet);
}